1bf215546Sopenharmony_ci/**********************************************************
2bf215546Sopenharmony_ci * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person
5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation
6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without
7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy,
8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies
9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is
10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be
13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22bf215546Sopenharmony_ci * SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci **********************************************************/
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "git_sha1.h" /* For MESA_GIT_SHA1 */
27bf215546Sopenharmony_ci#include "compiler/nir/nir.h"
28bf215546Sopenharmony_ci#include "util/format/u_format.h"
29bf215546Sopenharmony_ci#include "util/u_memory.h"
30bf215546Sopenharmony_ci#include "util/u_inlines.h"
31bf215546Sopenharmony_ci#include "util/u_screen.h"
32bf215546Sopenharmony_ci#include "util/u_string.h"
33bf215546Sopenharmony_ci#include "util/u_math.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "os/os_process.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "svga_winsys.h"
38bf215546Sopenharmony_ci#include "svga_public.h"
39bf215546Sopenharmony_ci#include "svga_context.h"
40bf215546Sopenharmony_ci#include "svga_format.h"
41bf215546Sopenharmony_ci#include "svga_screen.h"
42bf215546Sopenharmony_ci#include "svga_tgsi.h"
43bf215546Sopenharmony_ci#include "svga_resource_texture.h"
44bf215546Sopenharmony_ci#include "svga_resource.h"
45bf215546Sopenharmony_ci#include "svga_debug.h"
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci#include "svga3d_shaderdefs.h"
48bf215546Sopenharmony_ci#include "VGPU10ShaderTokens.h"
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/* NOTE: this constant may get moved into a svga3d*.h header file */
51bf215546Sopenharmony_ci#define SVGA3D_DX_MAX_RESOURCE_SIZE (128 * 1024 * 1024)
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci#ifndef MESA_GIT_SHA1
54bf215546Sopenharmony_ci#define MESA_GIT_SHA1 "(unknown git revision)"
55bf215546Sopenharmony_ci#endif
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci#ifdef DEBUG
58bf215546Sopenharmony_ciint SVGA_DEBUG = 0;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_cistatic const struct debug_named_value svga_debug_flags[] = {
61bf215546Sopenharmony_ci   { "dma",         DEBUG_DMA, NULL },
62bf215546Sopenharmony_ci   { "tgsi",        DEBUG_TGSI, NULL },
63bf215546Sopenharmony_ci   { "pipe",        DEBUG_PIPE, NULL },
64bf215546Sopenharmony_ci   { "state",       DEBUG_STATE, NULL },
65bf215546Sopenharmony_ci   { "screen",      DEBUG_SCREEN, NULL },
66bf215546Sopenharmony_ci   { "tex",         DEBUG_TEX, NULL },
67bf215546Sopenharmony_ci   { "swtnl",       DEBUG_SWTNL, NULL },
68bf215546Sopenharmony_ci   { "const",       DEBUG_CONSTS, NULL },
69bf215546Sopenharmony_ci   { "viewport",    DEBUG_VIEWPORT, NULL },
70bf215546Sopenharmony_ci   { "views",       DEBUG_VIEWS, NULL },
71bf215546Sopenharmony_ci   { "perf",        DEBUG_PERF, NULL },
72bf215546Sopenharmony_ci   { "flush",       DEBUG_FLUSH, NULL },
73bf215546Sopenharmony_ci   { "sync",        DEBUG_SYNC, NULL },
74bf215546Sopenharmony_ci   { "cache",       DEBUG_CACHE, NULL },
75bf215546Sopenharmony_ci   { "streamout",   DEBUG_STREAMOUT, NULL },
76bf215546Sopenharmony_ci   { "query",       DEBUG_QUERY, NULL },
77bf215546Sopenharmony_ci   { "samplers",    DEBUG_SAMPLERS, NULL },
78bf215546Sopenharmony_ci   { "image",       DEBUG_IMAGE, NULL },
79bf215546Sopenharmony_ci   { "uav",         DEBUG_UAV, NULL },
80bf215546Sopenharmony_ci   { "retry",       DEBUG_RETRY, NULL },
81bf215546Sopenharmony_ci   DEBUG_NAMED_VALUE_END
82bf215546Sopenharmony_ci};
83bf215546Sopenharmony_ci#endif
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_cistatic const char *
86bf215546Sopenharmony_cisvga_get_vendor( struct pipe_screen *pscreen )
87bf215546Sopenharmony_ci{
88bf215546Sopenharmony_ci   return "VMware, Inc.";
89bf215546Sopenharmony_ci}
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_cistatic const char *
93bf215546Sopenharmony_cisvga_get_name( struct pipe_screen *pscreen )
94bf215546Sopenharmony_ci{
95bf215546Sopenharmony_ci   const char *build = "", *llvm = "", *mutex = "";
96bf215546Sopenharmony_ci   static char name[100];
97bf215546Sopenharmony_ci#ifdef DEBUG
98bf215546Sopenharmony_ci   /* Only return internal details in the DEBUG version:
99bf215546Sopenharmony_ci    */
100bf215546Sopenharmony_ci   build = "build: DEBUG;";
101bf215546Sopenharmony_ci   mutex = "mutex: " PIPE_ATOMIC ";";
102bf215546Sopenharmony_ci#else
103bf215546Sopenharmony_ci   build = "build: RELEASE;";
104bf215546Sopenharmony_ci#endif
105bf215546Sopenharmony_ci#ifdef DRAW_LLVM_AVAILABLE
106bf215546Sopenharmony_ci   llvm = "LLVM;";
107bf215546Sopenharmony_ci#endif
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   snprintf(name, sizeof(name), "SVGA3D; %s %s %s", build, mutex, llvm);
110bf215546Sopenharmony_ci   return name;
111bf215546Sopenharmony_ci}
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci/** Helper for querying float-valued device cap */
115bf215546Sopenharmony_cistatic float
116bf215546Sopenharmony_ciget_float_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
117bf215546Sopenharmony_ci              float defaultVal)
118bf215546Sopenharmony_ci{
119bf215546Sopenharmony_ci   SVGA3dDevCapResult result;
120bf215546Sopenharmony_ci   if (sws->get_cap(sws, cap, &result))
121bf215546Sopenharmony_ci      return result.f;
122bf215546Sopenharmony_ci   else
123bf215546Sopenharmony_ci      return defaultVal;
124bf215546Sopenharmony_ci}
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci/** Helper for querying uint-valued device cap */
128bf215546Sopenharmony_cistatic unsigned
129bf215546Sopenharmony_ciget_uint_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
130bf215546Sopenharmony_ci             unsigned defaultVal)
131bf215546Sopenharmony_ci{
132bf215546Sopenharmony_ci   SVGA3dDevCapResult result;
133bf215546Sopenharmony_ci   if (sws->get_cap(sws, cap, &result))
134bf215546Sopenharmony_ci      return result.u;
135bf215546Sopenharmony_ci   else
136bf215546Sopenharmony_ci      return defaultVal;
137bf215546Sopenharmony_ci}
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci/** Helper for querying boolean-valued device cap */
141bf215546Sopenharmony_cistatic boolean
142bf215546Sopenharmony_ciget_bool_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
143bf215546Sopenharmony_ci             boolean defaultVal)
144bf215546Sopenharmony_ci{
145bf215546Sopenharmony_ci   SVGA3dDevCapResult result;
146bf215546Sopenharmony_ci   if (sws->get_cap(sws, cap, &result))
147bf215546Sopenharmony_ci      return result.b;
148bf215546Sopenharmony_ci   else
149bf215546Sopenharmony_ci      return defaultVal;
150bf215546Sopenharmony_ci}
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_cistatic float
154bf215546Sopenharmony_cisvga_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
155bf215546Sopenharmony_ci{
156bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
157bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   switch (param) {
160bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH:
161bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH_AA:
162bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE:
163bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE_AA:
164bf215546Sopenharmony_ci      return 1;
165bf215546Sopenharmony_ci   case PIPE_CAPF_POINT_SIZE_GRANULARITY:
166bf215546Sopenharmony_ci   case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
167bf215546Sopenharmony_ci      return 0.1;
168bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH:
169bf215546Sopenharmony_ci      return svgascreen->maxLineWidth;
170bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
171bf215546Sopenharmony_ci      return svgascreen->maxLineWidthAA;
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE:
174bf215546Sopenharmony_ci      FALLTHROUGH;
175bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE_AA:
176bf215546Sopenharmony_ci      return svgascreen->maxPointSize;
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
179bf215546Sopenharmony_ci      return (float) get_uint_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY, 4);
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
182bf215546Sopenharmony_ci      return 15.0;
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
185bf215546Sopenharmony_ci      FALLTHROUGH;
186bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
187bf215546Sopenharmony_ci      FALLTHROUGH;
188bf215546Sopenharmony_ci   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
189bf215546Sopenharmony_ci      return 0.0f;
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci   }
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci   debug_printf("Unexpected PIPE_CAPF_ query %u\n", param);
194bf215546Sopenharmony_ci   return 0;
195bf215546Sopenharmony_ci}
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_cistatic int
199bf215546Sopenharmony_cisvga_get_param(struct pipe_screen *screen, enum pipe_cap param)
200bf215546Sopenharmony_ci{
201bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
202bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
203bf215546Sopenharmony_ci   SVGA3dDevCapResult result;
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci   switch (param) {
206bf215546Sopenharmony_ci   case PIPE_CAP_NPOT_TEXTURES:
207bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
208bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
209bf215546Sopenharmony_ci      return 1;
210bf215546Sopenharmony_ci   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
211bf215546Sopenharmony_ci      /*
212bf215546Sopenharmony_ci       * "In virtually every OpenGL implementation and hardware,
213bf215546Sopenharmony_ci       * GL_MAX_DUAL_SOURCE_DRAW_BUFFERS is 1"
214bf215546Sopenharmony_ci       * http://www.opengl.org/wiki/Blending
215bf215546Sopenharmony_ci       */
216bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 1 : 0;
217bf215546Sopenharmony_ci   case PIPE_CAP_ANISOTROPIC_FILTER:
218bf215546Sopenharmony_ci      return 1;
219bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SPRITE:
220bf215546Sopenharmony_ci      return 1;
221bf215546Sopenharmony_ci   case PIPE_CAP_MAX_RENDER_TARGETS:
222bf215546Sopenharmony_ci      return svgascreen->max_color_buffers;
223bf215546Sopenharmony_ci   case PIPE_CAP_OCCLUSION_QUERY:
224bf215546Sopenharmony_ci      return 1;
225bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
226bf215546Sopenharmony_ci      return sws->have_vgpu10;
227bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
228bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 16 : 0;
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SWIZZLE:
231bf215546Sopenharmony_ci      return 1;
232bf215546Sopenharmony_ci   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
233bf215546Sopenharmony_ci      return 256;
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
236bf215546Sopenharmony_ci      {
237bf215546Sopenharmony_ci         unsigned size = 1 << (SVGA_MAX_TEXTURE_LEVELS - 1);
238bf215546Sopenharmony_ci         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH, &result))
239bf215546Sopenharmony_ci            size = MIN2(result.u, size);
240bf215546Sopenharmony_ci         else
241bf215546Sopenharmony_ci            size = 2048;
242bf215546Sopenharmony_ci         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT, &result))
243bf215546Sopenharmony_ci            size = MIN2(result.u, size);
244bf215546Sopenharmony_ci         else
245bf215546Sopenharmony_ci            size = 2048;
246bf215546Sopenharmony_ci         return size;
247bf215546Sopenharmony_ci      }
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
250bf215546Sopenharmony_ci      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VOLUME_EXTENT, &result))
251bf215546Sopenharmony_ci         return 8;  /* max 128x128x128 */
252bf215546Sopenharmony_ci      return MIN2(util_logbase2(result.u) + 1, SVGA_MAX_TEXTURE_LEVELS);
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
255bf215546Sopenharmony_ci      /*
256bf215546Sopenharmony_ci       * No mechanism to query the host, and at least limited to 2048x2048 on
257bf215546Sopenharmony_ci       * certain hardware.
258bf215546Sopenharmony_ci       */
259bf215546Sopenharmony_ci      return MIN2(util_last_bit(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_SIZE)),
260bf215546Sopenharmony_ci                  12 /* 2048x2048 */);
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
263bf215546Sopenharmony_ci      return sws->have_sm5 ? SVGA3D_SM5_MAX_SURFACE_ARRAYSIZE :
264bf215546Sopenharmony_ci             (sws->have_vgpu10 ? SVGA3D_SM4_MAX_SURFACE_ARRAYSIZE : 0);
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_SEPARATE: /* req. for GL 1.5 */
267bf215546Sopenharmony_ci      return 1;
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
270bf215546Sopenharmony_ci      return 1;
271bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
272bf215546Sopenharmony_ci      return sws->have_vgpu10;
273bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
274bf215546Sopenharmony_ci      return !sws->have_vgpu10;
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
277bf215546Sopenharmony_ci      return 1; /* The color outputs of vertex shaders are not clamped */
278bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
279bf215546Sopenharmony_ci      return sws->have_vgpu10;
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
282bf215546Sopenharmony_ci      return 1; /* expected for GL_ARB_framebuffer_object */
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL:
285bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
286bf215546Sopenharmony_ci      if (sws->have_gl43) {
287bf215546Sopenharmony_ci         return 430;
288bf215546Sopenharmony_ci      } else if (sws->have_sm5) {
289bf215546Sopenharmony_ci         return 410;
290bf215546Sopenharmony_ci      } else if (sws->have_vgpu10) {
291bf215546Sopenharmony_ci         return 330;
292bf215546Sopenharmony_ci      } else {
293bf215546Sopenharmony_ci         return 120;
294bf215546Sopenharmony_ci      }
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_TRANSFER_MODES:
297bf215546Sopenharmony_ci      return 0;
298bf215546Sopenharmony_ci
299bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
300bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
301bf215546Sopenharmony_ci      return 1;
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE:
304bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_ENABLE:
305bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER:
306bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIMESTAMP:
307bf215546Sopenharmony_ci   case PIPE_CAP_VS_INSTANCEID:
308bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
309bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP:
310bf215546Sopenharmony_ci   case PIPE_CAP_FAKE_SW_MSAA:
311bf215546Sopenharmony_ci      return sws->have_vgpu10;
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
314bf215546Sopenharmony_ci      return sws->have_vgpu10 ? SVGA3D_DX_MAX_SOTARGETS : 0;
315bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
316bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 4 : 0;
317bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
318bf215546Sopenharmony_ci      return sws->have_sm5 ? SVGA3D_MAX_STREAMOUT_DECLS :
319bf215546Sopenharmony_ci             (sws->have_vgpu10 ? SVGA3D_MAX_DX10_STREAMOUT_DECLS : 0);
320bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
321bf215546Sopenharmony_ci      return sws->have_sm5;
322bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
323bf215546Sopenharmony_ci      return sws->have_sm5;
324bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MULTISAMPLE:
325bf215546Sopenharmony_ci      return svgascreen->ms_samples ? 1 : 0;
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
328bf215546Sopenharmony_ci      /* convert bytes to texels for the case of the largest texel
329bf215546Sopenharmony_ci       * size: float[4].
330bf215546Sopenharmony_ci       */
331bf215546Sopenharmony_ci      return SVGA3D_DX_MAX_RESOURCE_SIZE / (4 * sizeof(float));
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXEL_OFFSET:
334bf215546Sopenharmony_ci      return sws->have_vgpu10 ? VGPU10_MIN_TEXEL_FETCH_OFFSET : 0;
335bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_OFFSET:
336bf215546Sopenharmony_ci      return sws->have_vgpu10 ? VGPU10_MAX_TEXEL_FETCH_OFFSET : 0;
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
339bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
340bf215546Sopenharmony_ci      return 0;
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
343bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 256 : 0;
344bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
345bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 1024 : 0;
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART:
348bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
349bf215546Sopenharmony_ci      return 1; /* may be a sw fallback, depending on restart index */
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci   case PIPE_CAP_GENERATE_MIPMAP:
352bf215546Sopenharmony_ci      return sws->have_generate_mipmap_cmd;
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   case PIPE_CAP_NATIVE_FENCE_FD:
355bf215546Sopenharmony_ci      return sws->have_fence_fd;
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
358bf215546Sopenharmony_ci      return 1;
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci   case PIPE_CAP_CUBE_MAP_ARRAY:
361bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_FUNC:
362bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLE_SHADING:
363bf215546Sopenharmony_ci   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
364bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_LOD:
365bf215546Sopenharmony_ci      return sws->have_sm4_1;
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
368bf215546Sopenharmony_ci      /* SM4_1 supports only single-channel textures where as SM5 supports
369bf215546Sopenharmony_ci       * all four channel textures */
370bf215546Sopenharmony_ci      return sws->have_sm5 ? 4 :
371bf215546Sopenharmony_ci             (sws->have_sm4_1 ? 1 : 0);
372bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_INDIRECT:
373bf215546Sopenharmony_ci      return sws->have_sm5;
374bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_STREAMS:
375bf215546Sopenharmony_ci      return sws->have_sm5 ? 4 : 0;
376bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE:
377bf215546Sopenharmony_ci      return sws->have_gl43;
378bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VARYINGS:
379bf215546Sopenharmony_ci      /* According to the spec, max varyings does not include the components
380bf215546Sopenharmony_ci       * for position, so remove one count from the max for position.
381bf215546Sopenharmony_ci       */
382bf215546Sopenharmony_ci      return sws->have_vgpu10 ? VGPU10_MAX_FS_INPUTS-1 : 10;
383bf215546Sopenharmony_ci   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
384bf215546Sopenharmony_ci      return sws->have_coherent;
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_ci   case PIPE_CAP_START_INSTANCE:
387bf215546Sopenharmony_ci      return sws->have_sm5;
388bf215546Sopenharmony_ci   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
389bf215546Sopenharmony_ci      return sws->have_sm5;
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_VIEW_TARGET:
392bf215546Sopenharmony_ci      return sws->have_gl43;
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
395bf215546Sopenharmony_ci      return sws->have_gl43;
396bf215546Sopenharmony_ci
397bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_HALFZ:
398bf215546Sopenharmony_ci      return sws->have_gl43;
399bf215546Sopenharmony_ci   case PIPE_CAP_SHAREABLE_SHADERS:
400bf215546Sopenharmony_ci      return 0;
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci   case PIPE_CAP_PCI_GROUP:
403bf215546Sopenharmony_ci   case PIPE_CAP_PCI_BUS:
404bf215546Sopenharmony_ci   case PIPE_CAP_PCI_DEVICE:
405bf215546Sopenharmony_ci   case PIPE_CAP_PCI_FUNCTION:
406bf215546Sopenharmony_ci      return 0;
407bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
408bf215546Sopenharmony_ci      return sws->have_gl43 ? 16 : 0;
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
411bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
412bf215546Sopenharmony_ci      return sws->have_gl43 ? SVGA_MAX_SHADER_BUFFERS : 0;
413bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
414bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
415bf215546Sopenharmony_ci      return sws->have_gl43 ? SVGA_MAX_ATOMIC_BUFFERS : 0;
416bf215546Sopenharmony_ci   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
417bf215546Sopenharmony_ci      return 64;
418bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
419bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
420bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
421bf215546Sopenharmony_ci      return 1;  /* need 4-byte alignment for all offsets and strides */
422bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
423bf215546Sopenharmony_ci      return 2048;
424bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VIEWPORTS:
425bf215546Sopenharmony_ci      assert((!sws->have_vgpu10 && svgascreen->max_viewports == 1) ||
426bf215546Sopenharmony_ci             (sws->have_vgpu10 &&
427bf215546Sopenharmony_ci              svgascreen->max_viewports == SVGA3D_DX_MAX_VIEWPORTS));
428bf215546Sopenharmony_ci      return svgascreen->max_viewports;
429bf215546Sopenharmony_ci   case PIPE_CAP_ENDIANNESS:
430bf215546Sopenharmony_ci      return PIPE_ENDIAN_LITTLE;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci   case PIPE_CAP_VENDOR_ID:
433bf215546Sopenharmony_ci      return 0x15ad; /* VMware Inc. */
434bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_ID:
435bf215546Sopenharmony_ci      if (sws->device_id) {
436bf215546Sopenharmony_ci         return sws->device_id;
437bf215546Sopenharmony_ci      } else {
438bf215546Sopenharmony_ci         return 0x0405; /* assume SVGA II */
439bf215546Sopenharmony_ci      }
440bf215546Sopenharmony_ci   case PIPE_CAP_ACCELERATED:
441bf215546Sopenharmony_ci      return 0; /* XXX: */
442bf215546Sopenharmony_ci   case PIPE_CAP_VIDEO_MEMORY:
443bf215546Sopenharmony_ci      /* XXX: Query the host ? */
444bf215546Sopenharmony_ci      return 1;
445bf215546Sopenharmony_ci   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
446bf215546Sopenharmony_ci      return sws->have_vgpu10;
447bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_TEXTURE:
448bf215546Sopenharmony_ci      return sws->have_vgpu10;
449bf215546Sopenharmony_ci   case PIPE_CAP_DOUBLES:
450bf215546Sopenharmony_ci      return sws->have_sm5;
451bf215546Sopenharmony_ci   case PIPE_CAP_UMA:
452bf215546Sopenharmony_ci   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
453bf215546Sopenharmony_ci      return 0;
454bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_DIV:
455bf215546Sopenharmony_ci      return 1;
456bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GS_INVOCATIONS:
457bf215546Sopenharmony_ci      return 32;
458bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
459bf215546Sopenharmony_ci      return 1 << 27;
460bf215546Sopenharmony_ci   /* Verify this once protocol is finalized. Setting it to minimum value. */
461bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
462bf215546Sopenharmony_ci      return sws->have_sm5 ? 30 : 0;
463bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
464bf215546Sopenharmony_ci      return 1;
465bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
466bf215546Sopenharmony_ci      return 1;
467bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEXCOORD:
468bf215546Sopenharmony_ci      return sws->have_vgpu10 ? 1 : 0;
469bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_STORE_FORMATTED:
470bf215546Sopenharmony_ci      return sws->have_gl43;
471bf215546Sopenharmony_ci   default:
472bf215546Sopenharmony_ci      return u_pipe_screen_get_param_defaults(screen, param);
473bf215546Sopenharmony_ci   }
474bf215546Sopenharmony_ci}
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_cistatic int
478bf215546Sopenharmony_civgpu9_get_shader_param(struct pipe_screen *screen,
479bf215546Sopenharmony_ci                       enum pipe_shader_type shader,
480bf215546Sopenharmony_ci                       enum pipe_shader_cap param)
481bf215546Sopenharmony_ci{
482bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
483bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
484bf215546Sopenharmony_ci   unsigned val;
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ci   assert(!sws->have_vgpu10);
487bf215546Sopenharmony_ci
488bf215546Sopenharmony_ci   switch (shader)
489bf215546Sopenharmony_ci   {
490bf215546Sopenharmony_ci   case PIPE_SHADER_FRAGMENT:
491bf215546Sopenharmony_ci      switch (param)
492bf215546Sopenharmony_ci      {
493bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
494bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
495bf215546Sopenharmony_ci         return get_uint_cap(sws,
496bf215546Sopenharmony_ci                             SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS,
497bf215546Sopenharmony_ci                             512);
498bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
499bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
500bf215546Sopenharmony_ci         return 512;
501bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
502bf215546Sopenharmony_ci         return SVGA3D_MAX_NESTING_LEVEL;
503bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_INPUTS:
504bf215546Sopenharmony_ci         return 10;
505bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_OUTPUTS:
506bf215546Sopenharmony_ci         return svgascreen->max_color_buffers;
507bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
508bf215546Sopenharmony_ci         return 224 * sizeof(float[4]);
509bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
510bf215546Sopenharmony_ci         return 1;
511bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEMPS:
512bf215546Sopenharmony_ci         val = get_uint_cap(sws, SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS, 32);
513bf215546Sopenharmony_ci         return MIN2(val, SVGA3D_TEMPREG_MAX);
514bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
515bf215546Sopenharmony_ci         /*
516bf215546Sopenharmony_ci          * Although PS 3.0 has some addressing abilities it can only represent
517bf215546Sopenharmony_ci          * loops that can be statically determined and unrolled. Given we can
518bf215546Sopenharmony_ci          * only handle a subset of the cases that the gallium frontend already
519bf215546Sopenharmony_ci          * does it is better to defer loop unrolling to the gallium frontend.
520bf215546Sopenharmony_ci          */
521bf215546Sopenharmony_ci         return 0;
522bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_CONT_SUPPORTED:
523bf215546Sopenharmony_ci         return 0;
524bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
525bf215546Sopenharmony_ci         return 0;
526bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
527bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
528bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
529bf215546Sopenharmony_ci         return 0;
530bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_SUBROUTINES:
531bf215546Sopenharmony_ci         return 0;
532bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INT64_ATOMICS:
533bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INTEGERS:
534bf215546Sopenharmony_ci         return 0;
535bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16:
536bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16_DERIVATIVES:
537bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
538bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INT16:
539bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
540bf215546Sopenharmony_ci         return 0;
541bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
542bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
543bf215546Sopenharmony_ci         return 16;
544bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_PREFERRED_IR:
545bf215546Sopenharmony_ci         return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
546bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_SUPPORTED_IRS:
547bf215546Sopenharmony_ci         return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
548bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_DROUND_SUPPORTED:
549bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
550bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
551bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
552bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
553bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
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      }
558bf215546Sopenharmony_ci      /* If we get here, we failed to handle a cap above */
559bf215546Sopenharmony_ci      debug_printf("Unexpected fragment shader query %u\n", param);
560bf215546Sopenharmony_ci      return 0;
561bf215546Sopenharmony_ci   case PIPE_SHADER_VERTEX:
562bf215546Sopenharmony_ci      switch (param)
563bf215546Sopenharmony_ci      {
564bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
565bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
566bf215546Sopenharmony_ci         return get_uint_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS,
567bf215546Sopenharmony_ci                             512);
568bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
569bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
570bf215546Sopenharmony_ci         /* XXX: until we have vertex texture support */
571bf215546Sopenharmony_ci         return 0;
572bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
573bf215546Sopenharmony_ci         return SVGA3D_MAX_NESTING_LEVEL;
574bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_INPUTS:
575bf215546Sopenharmony_ci         return 16;
576bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_OUTPUTS:
577bf215546Sopenharmony_ci         return 10;
578bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
579bf215546Sopenharmony_ci         return 256 * sizeof(float[4]);
580bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
581bf215546Sopenharmony_ci         return 1;
582bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEMPS:
583bf215546Sopenharmony_ci         val = get_uint_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS, 32);
584bf215546Sopenharmony_ci         return MIN2(val, SVGA3D_TEMPREG_MAX);
585bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_CONT_SUPPORTED:
586bf215546Sopenharmony_ci         return 0;
587bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
588bf215546Sopenharmony_ci         return 0;
589bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
590bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
591bf215546Sopenharmony_ci         return 1;
592bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
593bf215546Sopenharmony_ci         return 0;
594bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
595bf215546Sopenharmony_ci         return 1;
596bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_SUBROUTINES:
597bf215546Sopenharmony_ci         return 0;
598bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INT64_ATOMICS:
599bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INTEGERS:
600bf215546Sopenharmony_ci         return 0;
601bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16:
602bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16_DERIVATIVES:
603bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
604bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_INT16:
605bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
606bf215546Sopenharmony_ci         return 0;
607bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
608bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
609bf215546Sopenharmony_ci         return 0;
610bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_PREFERRED_IR:
611bf215546Sopenharmony_ci         return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
612bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_SUPPORTED_IRS:
613bf215546Sopenharmony_ci         return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
614bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_DROUND_SUPPORTED:
615bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
616bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
617bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
618bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
619bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
620bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
621bf215546Sopenharmony_ci      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
622bf215546Sopenharmony_ci         return 0;
623bf215546Sopenharmony_ci      }
624bf215546Sopenharmony_ci      /* If we get here, we failed to handle a cap above */
625bf215546Sopenharmony_ci      debug_printf("Unexpected vertex shader query %u\n", param);
626bf215546Sopenharmony_ci      return 0;
627bf215546Sopenharmony_ci   case PIPE_SHADER_GEOMETRY:
628bf215546Sopenharmony_ci   case PIPE_SHADER_COMPUTE:
629bf215546Sopenharmony_ci   case PIPE_SHADER_TESS_CTRL:
630bf215546Sopenharmony_ci   case PIPE_SHADER_TESS_EVAL:
631bf215546Sopenharmony_ci      /* no support for geometry, tess or compute shaders at this time */
632bf215546Sopenharmony_ci      return 0;
633bf215546Sopenharmony_ci   default:
634bf215546Sopenharmony_ci      debug_printf("Unexpected shader type (%u) query\n", shader);
635bf215546Sopenharmony_ci      return 0;
636bf215546Sopenharmony_ci   }
637bf215546Sopenharmony_ci   return 0;
638bf215546Sopenharmony_ci}
639bf215546Sopenharmony_ci
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_cistatic int
642bf215546Sopenharmony_civgpu10_get_shader_param(struct pipe_screen *screen,
643bf215546Sopenharmony_ci                        enum pipe_shader_type shader,
644bf215546Sopenharmony_ci                        enum pipe_shader_cap param)
645bf215546Sopenharmony_ci{
646bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
647bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_ci   assert(sws->have_vgpu10);
650bf215546Sopenharmony_ci   (void) sws;  /* silence unused var warnings in non-debug builds */
651bf215546Sopenharmony_ci
652bf215546Sopenharmony_ci   if ((!sws->have_sm5) &&
653bf215546Sopenharmony_ci       (shader == PIPE_SHADER_TESS_CTRL || shader == PIPE_SHADER_TESS_EVAL))
654bf215546Sopenharmony_ci      return 0;
655bf215546Sopenharmony_ci
656bf215546Sopenharmony_ci   if ((!sws->have_gl43) && (shader == PIPE_SHADER_COMPUTE))
657bf215546Sopenharmony_ci      return 0;
658bf215546Sopenharmony_ci
659bf215546Sopenharmony_ci   /* NOTE: we do not query the device for any caps/limits at this time */
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_ci   /* Generally the same limits for vertex, geometry and fragment shaders */
662bf215546Sopenharmony_ci   switch (param) {
663bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
664bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
665bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
666bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
667bf215546Sopenharmony_ci      return 64 * 1024;
668bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
669bf215546Sopenharmony_ci      return 64;
670bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INPUTS:
671bf215546Sopenharmony_ci      if (shader == PIPE_SHADER_FRAGMENT)
672bf215546Sopenharmony_ci         return VGPU10_MAX_FS_INPUTS;
673bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_GEOMETRY)
674bf215546Sopenharmony_ci         return svgascreen->max_gs_inputs;
675bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_TESS_CTRL)
676bf215546Sopenharmony_ci         return VGPU11_MAX_HS_INPUT_CONTROL_POINTS;
677bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_TESS_EVAL)
678bf215546Sopenharmony_ci         return VGPU11_MAX_DS_INPUT_CONTROL_POINTS;
679bf215546Sopenharmony_ci      else
680bf215546Sopenharmony_ci         return svgascreen->max_vs_inputs;
681bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_OUTPUTS:
682bf215546Sopenharmony_ci      if (shader == PIPE_SHADER_FRAGMENT)
683bf215546Sopenharmony_ci         return VGPU10_MAX_FS_OUTPUTS;
684bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_GEOMETRY)
685bf215546Sopenharmony_ci         return VGPU10_MAX_GS_OUTPUTS;
686bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_TESS_CTRL)
687bf215546Sopenharmony_ci         return VGPU11_MAX_HS_OUTPUTS;
688bf215546Sopenharmony_ci      else if (shader == PIPE_SHADER_TESS_EVAL)
689bf215546Sopenharmony_ci         return VGPU11_MAX_DS_OUTPUTS;
690bf215546Sopenharmony_ci      else
691bf215546Sopenharmony_ci         return svgascreen->max_vs_outputs;
692bf215546Sopenharmony_ci
693bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
694bf215546Sopenharmony_ci      return VGPU10_MAX_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]);
695bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
696bf215546Sopenharmony_ci      return svgascreen->max_const_buffers;
697bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEMPS:
698bf215546Sopenharmony_ci      return VGPU10_MAX_TEMPS;
699bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
700bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
701bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
702bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
703bf215546Sopenharmony_ci      return TRUE; /* XXX verify */
704bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_CONT_SUPPORTED:
705bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
706bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUBROUTINES:
707bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INTEGERS:
708bf215546Sopenharmony_ci      return TRUE;
709bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16:
710bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_DERIVATIVES:
711bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
712bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT16:
713bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
714bf215546Sopenharmony_ci      return FALSE;
715bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
716bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
717bf215546Sopenharmony_ci      return sws->have_gl43 ? PIPE_MAX_SAMPLERS : SVGA3D_DX_MAX_SAMPLERS;
718bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_PREFERRED_IR:
719bf215546Sopenharmony_ci         return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
720bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUPPORTED_IRS:
721bf215546Sopenharmony_ci      if (sws->have_gl43)
722bf215546Sopenharmony_ci         return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
723bf215546Sopenharmony_ci      else
724bf215546Sopenharmony_ci         return 0;
725bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DROUND_SUPPORTED:
726bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
727bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
728bf215546Sopenharmony_ci      /* For the above cases, we rely on the GLSL compiler to translate/lower
729bf215546Sopenharmony_ci       * the TGIS instruction into other instructions we do support.
730bf215546Sopenharmony_ci       */
731bf215546Sopenharmony_ci      return 0;
732bf215546Sopenharmony_ci
733bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
734bf215546Sopenharmony_ci      return sws->have_gl43 ? SVGA_MAX_IMAGES : 0;
735bf215546Sopenharmony_ci
736bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
737bf215546Sopenharmony_ci      return sws->have_gl43 ? SVGA_MAX_SHADER_BUFFERS : 0;
738bf215546Sopenharmony_ci
739bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
740bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
741bf215546Sopenharmony_ci      return sws->have_gl43 ? SVGA_MAX_ATOMIC_BUFFERS : 0;
742bf215546Sopenharmony_ci
743bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
744bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT64_ATOMICS:
745bf215546Sopenharmony_ci      return 0;
746bf215546Sopenharmony_ci   default:
747bf215546Sopenharmony_ci      debug_printf("Unexpected vgpu10 shader query %u\n", param);
748bf215546Sopenharmony_ci      return 0;
749bf215546Sopenharmony_ci   }
750bf215546Sopenharmony_ci   return 0;
751bf215546Sopenharmony_ci}
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_ci#define COMMON_OPTIONS                                                        \
754bf215546Sopenharmony_ci   .lower_extract_byte = true,                                                \
755bf215546Sopenharmony_ci   .lower_extract_word = true,                                                \
756bf215546Sopenharmony_ci   .lower_insert_byte = true,                                                 \
757bf215546Sopenharmony_ci   .lower_insert_word = true,                                                 \
758bf215546Sopenharmony_ci   .lower_int64_options = nir_lower_imul_2x32_64,                             \
759bf215546Sopenharmony_ci   .lower_fdph = true,                                                        \
760bf215546Sopenharmony_ci   .lower_flrp64 = true,                                                      \
761bf215546Sopenharmony_ci   .lower_rotate = true,                                                      \
762bf215546Sopenharmony_ci   .lower_uniforms_to_ubo = true,                                             \
763bf215546Sopenharmony_ci   .lower_vector_cmp = true,                                                  \
764bf215546Sopenharmony_ci   .max_unroll_iterations = 32,                                               \
765bf215546Sopenharmony_ci   .use_interpolated_input_intrinsics = true
766bf215546Sopenharmony_ci
767bf215546Sopenharmony_ci#define VGPU10_OPTIONS                                                        \
768bf215546Sopenharmony_ci   .lower_doubles_options = nir_lower_dfloor,                                 \
769bf215546Sopenharmony_ci   .lower_fmod = true,                                                        \
770bf215546Sopenharmony_ci   .lower_fpow = true
771bf215546Sopenharmony_ci
772bf215546Sopenharmony_cistatic const nir_shader_compiler_options svga_vgpu9_fragment_compiler_options = {
773bf215546Sopenharmony_ci   COMMON_OPTIONS,
774bf215546Sopenharmony_ci   .lower_bitops = true,
775bf215546Sopenharmony_ci   .force_indirect_unrolling = nir_var_all,
776bf215546Sopenharmony_ci   .force_indirect_unrolling_sampler = true,
777bf215546Sopenharmony_ci};
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_cistatic const nir_shader_compiler_options svga_vgpu9_vertex_compiler_options = {
780bf215546Sopenharmony_ci   COMMON_OPTIONS,
781bf215546Sopenharmony_ci   .lower_bitops = true,
782bf215546Sopenharmony_ci   .force_indirect_unrolling = nir_var_function_temp,
783bf215546Sopenharmony_ci   .force_indirect_unrolling_sampler = true,
784bf215546Sopenharmony_ci};
785bf215546Sopenharmony_ci
786bf215546Sopenharmony_cistatic const nir_shader_compiler_options svga_vgpu10_compiler_options = {
787bf215546Sopenharmony_ci   COMMON_OPTIONS,
788bf215546Sopenharmony_ci   VGPU10_OPTIONS,
789bf215546Sopenharmony_ci   .force_indirect_unrolling_sampler = true,
790bf215546Sopenharmony_ci};
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_cistatic const nir_shader_compiler_options svga_gl4_compiler_options = {
793bf215546Sopenharmony_ci   COMMON_OPTIONS,
794bf215546Sopenharmony_ci   VGPU10_OPTIONS,
795bf215546Sopenharmony_ci};
796bf215546Sopenharmony_ci
797bf215546Sopenharmony_cistatic const void *
798bf215546Sopenharmony_cisvga_get_compiler_options(struct pipe_screen *pscreen,
799bf215546Sopenharmony_ci                          enum pipe_shader_ir ir,
800bf215546Sopenharmony_ci                          enum pipe_shader_type shader)
801bf215546Sopenharmony_ci{
802bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(pscreen);
803bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
804bf215546Sopenharmony_ci
805bf215546Sopenharmony_ci   assert(ir == PIPE_SHADER_IR_NIR);
806bf215546Sopenharmony_ci
807bf215546Sopenharmony_ci   if (sws->have_gl43 || sws->have_sm5)
808bf215546Sopenharmony_ci      return &svga_gl4_compiler_options;
809bf215546Sopenharmony_ci   else if (sws->have_vgpu10)
810bf215546Sopenharmony_ci      return &svga_vgpu10_compiler_options;
811bf215546Sopenharmony_ci   else {
812bf215546Sopenharmony_ci      if (shader == PIPE_SHADER_FRAGMENT)
813bf215546Sopenharmony_ci         return &svga_vgpu9_fragment_compiler_options;
814bf215546Sopenharmony_ci      else
815bf215546Sopenharmony_ci         return &svga_vgpu9_vertex_compiler_options;
816bf215546Sopenharmony_ci   }
817bf215546Sopenharmony_ci}
818bf215546Sopenharmony_ci
819bf215546Sopenharmony_cistatic int
820bf215546Sopenharmony_cisvga_get_shader_param(struct pipe_screen *screen, enum pipe_shader_type shader,
821bf215546Sopenharmony_ci                      enum pipe_shader_cap param)
822bf215546Sopenharmony_ci{
823bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
824bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svgascreen->sws;
825bf215546Sopenharmony_ci   if (sws->have_vgpu10) {
826bf215546Sopenharmony_ci      return vgpu10_get_shader_param(screen, shader, param);
827bf215546Sopenharmony_ci   }
828bf215546Sopenharmony_ci   else {
829bf215546Sopenharmony_ci      return vgpu9_get_shader_param(screen, shader, param);
830bf215546Sopenharmony_ci   }
831bf215546Sopenharmony_ci}
832bf215546Sopenharmony_ci
833bf215546Sopenharmony_ci
834bf215546Sopenharmony_cistatic int
835bf215546Sopenharmony_cisvga_sm5_get_compute_param(struct pipe_screen *screen,
836bf215546Sopenharmony_ci                           enum pipe_shader_ir ir_type,
837bf215546Sopenharmony_ci                           enum pipe_compute_cap param,
838bf215546Sopenharmony_ci                           void *ret)
839bf215546Sopenharmony_ci{
840bf215546Sopenharmony_ci   ASSERTED struct svga_screen *svgascreen = svga_screen(screen);
841bf215546Sopenharmony_ci   ASSERTED struct svga_winsys_screen *sws = svgascreen->sws;
842bf215546Sopenharmony_ci   uint64_t *iret = (uint64_t *)ret;
843bf215546Sopenharmony_ci
844bf215546Sopenharmony_ci   assert(sws->have_gl43);
845bf215546Sopenharmony_ci   assert(ir_type == PIPE_SHADER_IR_TGSI);
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci   switch (param) {
848bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
849bf215546Sopenharmony_ci      iret[0] = 65535;
850bf215546Sopenharmony_ci      iret[1] = 65535;
851bf215546Sopenharmony_ci      iret[2] = 65535;
852bf215546Sopenharmony_ci      return 3 * sizeof(uint64_t);
853bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
854bf215546Sopenharmony_ci      iret[0] = 1024;
855bf215546Sopenharmony_ci      iret[1] = 1024;
856bf215546Sopenharmony_ci      iret[2] = 64;
857bf215546Sopenharmony_ci      return 3 * sizeof(uint64_t);
858bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
859bf215546Sopenharmony_ci      *iret = 1024;
860bf215546Sopenharmony_ci      return sizeof(uint64_t);
861bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
862bf215546Sopenharmony_ci      *iret = 32768;
863bf215546Sopenharmony_ci      return sizeof(uint64_t);
864bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
865bf215546Sopenharmony_ci      *iret = 0;
866bf215546Sopenharmony_ci      return sizeof(uint64_t);
867bf215546Sopenharmony_ci   default:
868bf215546Sopenharmony_ci      debug_printf("Unexpected compute param %u\n", param);
869bf215546Sopenharmony_ci   }
870bf215546Sopenharmony_ci   return 0;
871bf215546Sopenharmony_ci}
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_cistatic void
874bf215546Sopenharmony_cisvga_fence_reference(struct pipe_screen *screen,
875bf215546Sopenharmony_ci                     struct pipe_fence_handle **ptr,
876bf215546Sopenharmony_ci                     struct pipe_fence_handle *fence)
877bf215546Sopenharmony_ci{
878bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
879bf215546Sopenharmony_ci   sws->fence_reference(sws, ptr, fence);
880bf215546Sopenharmony_ci}
881bf215546Sopenharmony_ci
882bf215546Sopenharmony_ci
883bf215546Sopenharmony_cistatic bool
884bf215546Sopenharmony_cisvga_fence_finish(struct pipe_screen *screen,
885bf215546Sopenharmony_ci                  struct pipe_context *ctx,
886bf215546Sopenharmony_ci                  struct pipe_fence_handle *fence,
887bf215546Sopenharmony_ci                  uint64_t timeout)
888bf215546Sopenharmony_ci{
889bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
890bf215546Sopenharmony_ci   bool retVal;
891bf215546Sopenharmony_ci
892bf215546Sopenharmony_ci   SVGA_STATS_TIME_PUSH(sws, SVGA_STATS_TIME_FENCEFINISH);
893bf215546Sopenharmony_ci
894bf215546Sopenharmony_ci   if (!timeout) {
895bf215546Sopenharmony_ci      retVal = sws->fence_signalled(sws, fence, 0) == 0;
896bf215546Sopenharmony_ci   }
897bf215546Sopenharmony_ci   else {
898bf215546Sopenharmony_ci      SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
899bf215546Sopenharmony_ci               __FUNCTION__, fence);
900bf215546Sopenharmony_ci
901bf215546Sopenharmony_ci      retVal = sws->fence_finish(sws, fence, timeout, 0) == 0;
902bf215546Sopenharmony_ci   }
903bf215546Sopenharmony_ci
904bf215546Sopenharmony_ci   SVGA_STATS_TIME_POP(sws);
905bf215546Sopenharmony_ci
906bf215546Sopenharmony_ci   return retVal;
907bf215546Sopenharmony_ci}
908bf215546Sopenharmony_ci
909bf215546Sopenharmony_ci
910bf215546Sopenharmony_cistatic int
911bf215546Sopenharmony_cisvga_fence_get_fd(struct pipe_screen *screen,
912bf215546Sopenharmony_ci                  struct pipe_fence_handle *fence)
913bf215546Sopenharmony_ci{
914bf215546Sopenharmony_ci   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
915bf215546Sopenharmony_ci
916bf215546Sopenharmony_ci   return sws->fence_get_fd(sws, fence, TRUE);
917bf215546Sopenharmony_ci}
918bf215546Sopenharmony_ci
919bf215546Sopenharmony_ci
920bf215546Sopenharmony_cistatic int
921bf215546Sopenharmony_cisvga_get_driver_query_info(struct pipe_screen *screen,
922bf215546Sopenharmony_ci                           unsigned index,
923bf215546Sopenharmony_ci                           struct pipe_driver_query_info *info)
924bf215546Sopenharmony_ci{
925bf215546Sopenharmony_ci#define QUERY(NAME, ENUM, UNITS) \
926bf215546Sopenharmony_ci   {NAME, ENUM, {0}, UNITS, PIPE_DRIVER_QUERY_RESULT_TYPE_AVERAGE, 0, 0x0}
927bf215546Sopenharmony_ci
928bf215546Sopenharmony_ci   static const struct pipe_driver_query_info queries[] = {
929bf215546Sopenharmony_ci      /* per-frame counters */
930bf215546Sopenharmony_ci      QUERY("num-draw-calls", SVGA_QUERY_NUM_DRAW_CALLS,
931bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
932bf215546Sopenharmony_ci      QUERY("num-fallbacks", SVGA_QUERY_NUM_FALLBACKS,
933bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
934bf215546Sopenharmony_ci      QUERY("num-flushes", SVGA_QUERY_NUM_FLUSHES,
935bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
936bf215546Sopenharmony_ci      QUERY("num-validations", SVGA_QUERY_NUM_VALIDATIONS,
937bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
938bf215546Sopenharmony_ci      QUERY("map-buffer-time", SVGA_QUERY_MAP_BUFFER_TIME,
939bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_MICROSECONDS),
940bf215546Sopenharmony_ci      QUERY("num-buffers-mapped", SVGA_QUERY_NUM_BUFFERS_MAPPED,
941bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
942bf215546Sopenharmony_ci      QUERY("num-textures-mapped", SVGA_QUERY_NUM_TEXTURES_MAPPED,
943bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
944bf215546Sopenharmony_ci      QUERY("num-bytes-uploaded", SVGA_QUERY_NUM_BYTES_UPLOADED,
945bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_BYTES),
946bf215546Sopenharmony_ci      QUERY("num-command-buffers", SVGA_QUERY_NUM_COMMAND_BUFFERS,
947bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
948bf215546Sopenharmony_ci      QUERY("command-buffer-size", SVGA_QUERY_COMMAND_BUFFER_SIZE,
949bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_BYTES),
950bf215546Sopenharmony_ci      QUERY("flush-time", SVGA_QUERY_FLUSH_TIME,
951bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_MICROSECONDS),
952bf215546Sopenharmony_ci      QUERY("surface-write-flushes", SVGA_QUERY_SURFACE_WRITE_FLUSHES,
953bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
954bf215546Sopenharmony_ci      QUERY("num-readbacks", SVGA_QUERY_NUM_READBACKS,
955bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
956bf215546Sopenharmony_ci      QUERY("num-resource-updates", SVGA_QUERY_NUM_RESOURCE_UPDATES,
957bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
958bf215546Sopenharmony_ci      QUERY("num-buffer-uploads", SVGA_QUERY_NUM_BUFFER_UPLOADS,
959bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
960bf215546Sopenharmony_ci      QUERY("num-const-buf-updates", SVGA_QUERY_NUM_CONST_BUF_UPDATES,
961bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
962bf215546Sopenharmony_ci      QUERY("num-const-updates", SVGA_QUERY_NUM_CONST_UPDATES,
963bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
964bf215546Sopenharmony_ci      QUERY("num-shader-relocations", SVGA_QUERY_NUM_SHADER_RELOCATIONS,
965bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
966bf215546Sopenharmony_ci      QUERY("num-surface-relocations", SVGA_QUERY_NUM_SURFACE_RELOCATIONS,
967bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
968bf215546Sopenharmony_ci
969bf215546Sopenharmony_ci      /* running total counters */
970bf215546Sopenharmony_ci      QUERY("memory-used", SVGA_QUERY_MEMORY_USED,
971bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_BYTES),
972bf215546Sopenharmony_ci      QUERY("num-shaders", SVGA_QUERY_NUM_SHADERS,
973bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
974bf215546Sopenharmony_ci      QUERY("num-resources", SVGA_QUERY_NUM_RESOURCES,
975bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
976bf215546Sopenharmony_ci      QUERY("num-state-objects", SVGA_QUERY_NUM_STATE_OBJECTS,
977bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
978bf215546Sopenharmony_ci      QUERY("num-surface-views", SVGA_QUERY_NUM_SURFACE_VIEWS,
979bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
980bf215546Sopenharmony_ci      QUERY("num-generate-mipmap", SVGA_QUERY_NUM_GENERATE_MIPMAP,
981bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
982bf215546Sopenharmony_ci      QUERY("num-failed-allocations", SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
983bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
984bf215546Sopenharmony_ci      QUERY("num-commands-per-draw", SVGA_QUERY_NUM_COMMANDS_PER_DRAW,
985bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_FLOAT),
986bf215546Sopenharmony_ci      QUERY("shader-mem-used", SVGA_QUERY_SHADER_MEM_USED,
987bf215546Sopenharmony_ci            PIPE_DRIVER_QUERY_TYPE_UINT64),
988bf215546Sopenharmony_ci   };
989bf215546Sopenharmony_ci#undef QUERY
990bf215546Sopenharmony_ci
991bf215546Sopenharmony_ci   if (!info)
992bf215546Sopenharmony_ci      return ARRAY_SIZE(queries);
993bf215546Sopenharmony_ci
994bf215546Sopenharmony_ci   if (index >= ARRAY_SIZE(queries))
995bf215546Sopenharmony_ci      return 0;
996bf215546Sopenharmony_ci
997bf215546Sopenharmony_ci   *info = queries[index];
998bf215546Sopenharmony_ci   return 1;
999bf215546Sopenharmony_ci}
1000bf215546Sopenharmony_ci
1001bf215546Sopenharmony_ci
1002bf215546Sopenharmony_cistatic void
1003bf215546Sopenharmony_ciinit_logging(struct pipe_screen *screen)
1004bf215546Sopenharmony_ci{
1005bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
1006bf215546Sopenharmony_ci   static const char *log_prefix = "Mesa: ";
1007bf215546Sopenharmony_ci   char host_log[1000];
1008bf215546Sopenharmony_ci
1009bf215546Sopenharmony_ci   /* Log Version to Host */
1010bf215546Sopenharmony_ci   snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
1011bf215546Sopenharmony_ci            "%s%s\n", log_prefix, svga_get_name(screen));
1012bf215546Sopenharmony_ci   svgascreen->sws->host_log(svgascreen->sws, host_log);
1013bf215546Sopenharmony_ci
1014bf215546Sopenharmony_ci   snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
1015bf215546Sopenharmony_ci            "%s" PACKAGE_VERSION MESA_GIT_SHA1, log_prefix);
1016bf215546Sopenharmony_ci   svgascreen->sws->host_log(svgascreen->sws, host_log);
1017bf215546Sopenharmony_ci
1018bf215546Sopenharmony_ci   /* If the SVGA_EXTRA_LOGGING env var is set, log the process's command
1019bf215546Sopenharmony_ci    * line (program name and arguments).
1020bf215546Sopenharmony_ci    */
1021bf215546Sopenharmony_ci   if (debug_get_bool_option("SVGA_EXTRA_LOGGING", FALSE)) {
1022bf215546Sopenharmony_ci      char cmdline[1000];
1023bf215546Sopenharmony_ci      if (os_get_command_line(cmdline, sizeof(cmdline))) {
1024bf215546Sopenharmony_ci         snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
1025bf215546Sopenharmony_ci                  "%s%s\n", log_prefix, cmdline);
1026bf215546Sopenharmony_ci         svgascreen->sws->host_log(svgascreen->sws, host_log);
1027bf215546Sopenharmony_ci      }
1028bf215546Sopenharmony_ci   }
1029bf215546Sopenharmony_ci}
1030bf215546Sopenharmony_ci
1031bf215546Sopenharmony_ci
1032bf215546Sopenharmony_ci/**
1033bf215546Sopenharmony_ci * no-op logging function to use when SVGA_NO_LOGGING is set.
1034bf215546Sopenharmony_ci */
1035bf215546Sopenharmony_cistatic void
1036bf215546Sopenharmony_cinop_host_log(struct svga_winsys_screen *sws, const char *message)
1037bf215546Sopenharmony_ci{
1038bf215546Sopenharmony_ci   /* nothing */
1039bf215546Sopenharmony_ci}
1040bf215546Sopenharmony_ci
1041bf215546Sopenharmony_ci
1042bf215546Sopenharmony_cistatic void
1043bf215546Sopenharmony_cisvga_destroy_screen( struct pipe_screen *screen )
1044bf215546Sopenharmony_ci{
1045bf215546Sopenharmony_ci   struct svga_screen *svgascreen = svga_screen(screen);
1046bf215546Sopenharmony_ci
1047bf215546Sopenharmony_ci   svga_screen_cache_cleanup(svgascreen);
1048bf215546Sopenharmony_ci
1049bf215546Sopenharmony_ci   mtx_destroy(&svgascreen->swc_mutex);
1050bf215546Sopenharmony_ci   mtx_destroy(&svgascreen->tex_mutex);
1051bf215546Sopenharmony_ci
1052bf215546Sopenharmony_ci   svgascreen->sws->destroy(svgascreen->sws);
1053bf215546Sopenharmony_ci
1054bf215546Sopenharmony_ci   FREE(svgascreen);
1055bf215546Sopenharmony_ci}
1056bf215546Sopenharmony_ci
1057bf215546Sopenharmony_ci
1058bf215546Sopenharmony_ci/**
1059bf215546Sopenharmony_ci * Create a new svga_screen object
1060bf215546Sopenharmony_ci */
1061bf215546Sopenharmony_cistruct pipe_screen *
1062bf215546Sopenharmony_cisvga_screen_create(struct svga_winsys_screen *sws)
1063bf215546Sopenharmony_ci{
1064bf215546Sopenharmony_ci   struct svga_screen *svgascreen;
1065bf215546Sopenharmony_ci   struct pipe_screen *screen;
1066bf215546Sopenharmony_ci
1067bf215546Sopenharmony_ci#ifdef DEBUG
1068bf215546Sopenharmony_ci   SVGA_DEBUG = debug_get_flags_option("SVGA_DEBUG", svga_debug_flags, 0 );
1069bf215546Sopenharmony_ci#endif
1070bf215546Sopenharmony_ci
1071bf215546Sopenharmony_ci   svgascreen = CALLOC_STRUCT(svga_screen);
1072bf215546Sopenharmony_ci   if (!svgascreen)
1073bf215546Sopenharmony_ci      goto error1;
1074bf215546Sopenharmony_ci
1075bf215546Sopenharmony_ci   svgascreen->debug.force_level_surface_view =
1076bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_FORCE_LEVEL_SURFACE_VIEW", FALSE);
1077bf215546Sopenharmony_ci   svgascreen->debug.force_surface_view =
1078bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_FORCE_SURFACE_VIEW", FALSE);
1079bf215546Sopenharmony_ci   svgascreen->debug.force_sampler_view =
1080bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_FORCE_SAMPLER_VIEW", FALSE);
1081bf215546Sopenharmony_ci   svgascreen->debug.no_surface_view =
1082bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_NO_SURFACE_VIEW", FALSE);
1083bf215546Sopenharmony_ci   svgascreen->debug.no_sampler_view =
1084bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_NO_SAMPLER_VIEW", FALSE);
1085bf215546Sopenharmony_ci   svgascreen->debug.no_cache_index_buffers =
1086bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_NO_CACHE_INDEX_BUFFERS", FALSE);
1087bf215546Sopenharmony_ci   svgascreen->debug.nir =
1088bf215546Sopenharmony_ci      debug_get_bool_option("SVGA_NIR", FALSE);
1089bf215546Sopenharmony_ci
1090bf215546Sopenharmony_ci   screen = &svgascreen->screen;
1091bf215546Sopenharmony_ci
1092bf215546Sopenharmony_ci   screen->destroy = svga_destroy_screen;
1093bf215546Sopenharmony_ci   screen->get_name = svga_get_name;
1094bf215546Sopenharmony_ci   screen->get_vendor = svga_get_vendor;
1095bf215546Sopenharmony_ci   screen->get_device_vendor = svga_get_vendor; // TODO actual device vendor
1096bf215546Sopenharmony_ci   screen->get_param = svga_get_param;
1097bf215546Sopenharmony_ci   screen->get_shader_param = svga_get_shader_param;
1098bf215546Sopenharmony_ci   screen->get_compiler_options = svga_get_compiler_options;
1099bf215546Sopenharmony_ci   screen->get_paramf = svga_get_paramf;
1100bf215546Sopenharmony_ci   screen->get_timestamp = NULL;
1101bf215546Sopenharmony_ci   screen->is_format_supported = svga_is_format_supported;
1102bf215546Sopenharmony_ci   screen->context_create = svga_context_create;
1103bf215546Sopenharmony_ci   screen->fence_reference = svga_fence_reference;
1104bf215546Sopenharmony_ci   screen->fence_finish = svga_fence_finish;
1105bf215546Sopenharmony_ci   screen->fence_get_fd = svga_fence_get_fd;
1106bf215546Sopenharmony_ci
1107bf215546Sopenharmony_ci   screen->get_driver_query_info = svga_get_driver_query_info;
1108bf215546Sopenharmony_ci
1109bf215546Sopenharmony_ci   screen->get_compute_param = svga_sm5_get_compute_param;
1110bf215546Sopenharmony_ci
1111bf215546Sopenharmony_ci   svgascreen->sws = sws;
1112bf215546Sopenharmony_ci
1113bf215546Sopenharmony_ci   svga_init_screen_resource_functions(svgascreen);
1114bf215546Sopenharmony_ci
1115bf215546Sopenharmony_ci   if (sws->get_hw_version) {
1116bf215546Sopenharmony_ci      svgascreen->hw_version = sws->get_hw_version(sws);
1117bf215546Sopenharmony_ci   } else {
1118bf215546Sopenharmony_ci      svgascreen->hw_version = SVGA3D_HWVERSION_WS65_B1;
1119bf215546Sopenharmony_ci   }
1120bf215546Sopenharmony_ci
1121bf215546Sopenharmony_ci   if (svgascreen->hw_version < SVGA3D_HWVERSION_WS8_B1) {
1122bf215546Sopenharmony_ci      /* too old for 3D acceleration */
1123bf215546Sopenharmony_ci      debug_printf("Hardware version 0x%x is too old for accerated 3D\n",
1124bf215546Sopenharmony_ci                   svgascreen->hw_version);
1125bf215546Sopenharmony_ci      goto error2;
1126bf215546Sopenharmony_ci   }
1127bf215546Sopenharmony_ci
1128bf215546Sopenharmony_ci   if (sws->have_gl43) {
1129bf215546Sopenharmony_ci      svgascreen->forcedSampleCount =
1130bf215546Sopenharmony_ci         get_uint_cap(sws, SVGA3D_DEVCAP_MAX_FORCED_SAMPLE_COUNT, 0);
1131bf215546Sopenharmony_ci
1132bf215546Sopenharmony_ci      sws->have_gl43 = sws->have_gl43 && (svgascreen->forcedSampleCount >= 4);
1133bf215546Sopenharmony_ci
1134bf215546Sopenharmony_ci      /* Allow a temporary environment variable to enable/disable GL43 support.
1135bf215546Sopenharmony_ci       */
1136bf215546Sopenharmony_ci      sws->have_gl43 =
1137bf215546Sopenharmony_ci         debug_get_bool_option("SVGA_GL43", sws->have_gl43);
1138bf215546Sopenharmony_ci
1139bf215546Sopenharmony_ci      svgascreen->debug.sampler_state_mapping =
1140bf215546Sopenharmony_ci         debug_get_bool_option("SVGA_SAMPLER_STATE_MAPPING", FALSE);
1141bf215546Sopenharmony_ci   }
1142bf215546Sopenharmony_ci   else {
1143bf215546Sopenharmony_ci      /* sampler state mapping code is only enabled with GL43
1144bf215546Sopenharmony_ci       * due to the limitation in SW Renderer. (VMware bug 2825014)
1145bf215546Sopenharmony_ci       */
1146bf215546Sopenharmony_ci      svgascreen->debug.sampler_state_mapping = FALSE;
1147bf215546Sopenharmony_ci   }
1148bf215546Sopenharmony_ci
1149bf215546Sopenharmony_ci   debug_printf("%s enabled\n",
1150bf215546Sopenharmony_ci                sws->have_gl43 ? "SM5+" :
1151bf215546Sopenharmony_ci                sws->have_sm5 ? "SM5" :
1152bf215546Sopenharmony_ci                sws->have_sm4_1 ? "SM4_1" :
1153bf215546Sopenharmony_ci                sws->have_vgpu10 ? "VGPU10" : "VGPU9");
1154bf215546Sopenharmony_ci
1155bf215546Sopenharmony_ci   debug_printf("Mesa: %s %s (%s)\n", svga_get_name(screen),
1156bf215546Sopenharmony_ci                PACKAGE_VERSION, MESA_GIT_SHA1);
1157bf215546Sopenharmony_ci
1158bf215546Sopenharmony_ci   /*
1159bf215546Sopenharmony_ci    * The D16, D24X8, and D24S8 formats always do an implicit shadow compare
1160bf215546Sopenharmony_ci    * when sampled from, where as the DF16, DF24, and D24S8_INT do not.  So
1161bf215546Sopenharmony_ci    * we prefer the later when available.
1162bf215546Sopenharmony_ci    *
1163bf215546Sopenharmony_ci    * This mimics hardware vendors extensions for D3D depth sampling. See also
1164bf215546Sopenharmony_ci    * http://aras-p.info/texts/D3D9GPUHacks.html
1165bf215546Sopenharmony_ci    */
1166bf215546Sopenharmony_ci
1167bf215546Sopenharmony_ci   {
1168bf215546Sopenharmony_ci      boolean has_df16, has_df24, has_d24s8_int;
1169bf215546Sopenharmony_ci      SVGA3dSurfaceFormatCaps caps;
1170bf215546Sopenharmony_ci      SVGA3dSurfaceFormatCaps mask;
1171bf215546Sopenharmony_ci      mask.value = 0;
1172bf215546Sopenharmony_ci      mask.zStencil = 1;
1173bf215546Sopenharmony_ci      mask.texture = 1;
1174bf215546Sopenharmony_ci
1175bf215546Sopenharmony_ci      svgascreen->depth.z16 = SVGA3D_Z_D16;
1176bf215546Sopenharmony_ci      svgascreen->depth.x8z24 = SVGA3D_Z_D24X8;
1177bf215546Sopenharmony_ci      svgascreen->depth.s8z24 = SVGA3D_Z_D24S8;
1178bf215546Sopenharmony_ci
1179bf215546Sopenharmony_ci      svga_get_format_cap(svgascreen, SVGA3D_Z_DF16, &caps);
1180bf215546Sopenharmony_ci      has_df16 = (caps.value & mask.value) == mask.value;
1181bf215546Sopenharmony_ci
1182bf215546Sopenharmony_ci      svga_get_format_cap(svgascreen, SVGA3D_Z_DF24, &caps);
1183bf215546Sopenharmony_ci      has_df24 = (caps.value & mask.value) == mask.value;
1184bf215546Sopenharmony_ci
1185bf215546Sopenharmony_ci      svga_get_format_cap(svgascreen, SVGA3D_Z_D24S8_INT, &caps);
1186bf215546Sopenharmony_ci      has_d24s8_int = (caps.value & mask.value) == mask.value;
1187bf215546Sopenharmony_ci
1188bf215546Sopenharmony_ci      /* XXX: We might want some other logic here.
1189bf215546Sopenharmony_ci       * Like if we only have d24s8_int we should
1190bf215546Sopenharmony_ci       * emulate the other formats with that.
1191bf215546Sopenharmony_ci       */
1192bf215546Sopenharmony_ci      if (has_df16) {
1193bf215546Sopenharmony_ci         svgascreen->depth.z16 = SVGA3D_Z_DF16;
1194bf215546Sopenharmony_ci      }
1195bf215546Sopenharmony_ci      if (has_df24) {
1196bf215546Sopenharmony_ci         svgascreen->depth.x8z24 = SVGA3D_Z_DF24;
1197bf215546Sopenharmony_ci      }
1198bf215546Sopenharmony_ci      if (has_d24s8_int) {
1199bf215546Sopenharmony_ci         svgascreen->depth.s8z24 = SVGA3D_Z_D24S8_INT;
1200bf215546Sopenharmony_ci      }
1201bf215546Sopenharmony_ci   }
1202bf215546Sopenharmony_ci
1203bf215546Sopenharmony_ci   /* Query device caps
1204bf215546Sopenharmony_ci    */
1205bf215546Sopenharmony_ci   if (sws->have_vgpu10) {
1206bf215546Sopenharmony_ci      svgascreen->haveProvokingVertex
1207bf215546Sopenharmony_ci         = get_bool_cap(sws, SVGA3D_DEVCAP_DX_PROVOKING_VERTEX, FALSE);
1208bf215546Sopenharmony_ci      svgascreen->haveLineSmooth = TRUE;
1209bf215546Sopenharmony_ci      svgascreen->maxPointSize = 80.0F;
1210bf215546Sopenharmony_ci      svgascreen->max_color_buffers = SVGA3D_DX_MAX_RENDER_TARGETS;
1211bf215546Sopenharmony_ci
1212bf215546Sopenharmony_ci      /* Multisample samples per pixel */
1213bf215546Sopenharmony_ci      if (sws->have_sm4_1 && debug_get_bool_option("SVGA_MSAA", TRUE)) {
1214bf215546Sopenharmony_ci         if (get_bool_cap(sws, SVGA3D_DEVCAP_MULTISAMPLE_2X, FALSE))
1215bf215546Sopenharmony_ci            svgascreen->ms_samples |= 1 << 1;
1216bf215546Sopenharmony_ci         if (get_bool_cap(sws, SVGA3D_DEVCAP_MULTISAMPLE_4X, FALSE))
1217bf215546Sopenharmony_ci            svgascreen->ms_samples |= 1 << 3;
1218bf215546Sopenharmony_ci      }
1219bf215546Sopenharmony_ci
1220bf215546Sopenharmony_ci      if (sws->have_sm5 && debug_get_bool_option("SVGA_MSAA", TRUE)) {
1221bf215546Sopenharmony_ci         if (get_bool_cap(sws, SVGA3D_DEVCAP_MULTISAMPLE_8X, FALSE))
1222bf215546Sopenharmony_ci            svgascreen->ms_samples |= 1 << 7;
1223bf215546Sopenharmony_ci      }
1224bf215546Sopenharmony_ci
1225bf215546Sopenharmony_ci      /* Maximum number of constant buffers */
1226bf215546Sopenharmony_ci      if (sws->have_gl43) {
1227bf215546Sopenharmony_ci         svgascreen->max_const_buffers = SVGA_MAX_CONST_BUFS;
1228bf215546Sopenharmony_ci      }
1229bf215546Sopenharmony_ci      else {
1230bf215546Sopenharmony_ci         svgascreen->max_const_buffers =
1231bf215546Sopenharmony_ci            get_uint_cap(sws, SVGA3D_DEVCAP_DX_MAX_CONSTANT_BUFFERS, 1);
1232bf215546Sopenharmony_ci         svgascreen->max_const_buffers = MIN2(svgascreen->max_const_buffers,
1233bf215546Sopenharmony_ci                                              SVGA_MAX_CONST_BUFS);
1234bf215546Sopenharmony_ci      }
1235bf215546Sopenharmony_ci
1236bf215546Sopenharmony_ci      svgascreen->haveBlendLogicops =
1237bf215546Sopenharmony_ci         get_bool_cap(sws, SVGA3D_DEVCAP_LOGIC_BLENDOPS, FALSE);
1238bf215546Sopenharmony_ci
1239bf215546Sopenharmony_ci      screen->is_format_supported = svga_is_dx_format_supported;
1240bf215546Sopenharmony_ci
1241bf215546Sopenharmony_ci      svgascreen->max_viewports = SVGA3D_DX_MAX_VIEWPORTS;
1242bf215546Sopenharmony_ci
1243bf215546Sopenharmony_ci      /* Shader limits */
1244bf215546Sopenharmony_ci      if (sws->have_sm4_1) {
1245bf215546Sopenharmony_ci         svgascreen->max_vs_inputs  = VGPU10_1_MAX_VS_INPUTS;
1246bf215546Sopenharmony_ci         svgascreen->max_vs_outputs = VGPU10_1_MAX_VS_OUTPUTS;
1247bf215546Sopenharmony_ci         svgascreen->max_gs_inputs  = VGPU10_1_MAX_GS_INPUTS;
1248bf215546Sopenharmony_ci      }
1249bf215546Sopenharmony_ci      else {
1250bf215546Sopenharmony_ci         svgascreen->max_vs_inputs  = VGPU10_MAX_VS_INPUTS;
1251bf215546Sopenharmony_ci         svgascreen->max_vs_outputs = VGPU10_MAX_VS_OUTPUTS;
1252bf215546Sopenharmony_ci         svgascreen->max_gs_inputs  = VGPU10_MAX_GS_INPUTS;
1253bf215546Sopenharmony_ci      }
1254bf215546Sopenharmony_ci   }
1255bf215546Sopenharmony_ci   else {
1256bf215546Sopenharmony_ci      /* VGPU9 */
1257bf215546Sopenharmony_ci      unsigned vs_ver = get_uint_cap(sws, SVGA3D_DEVCAP_VERTEX_SHADER_VERSION,
1258bf215546Sopenharmony_ci                                     SVGA3DVSVERSION_NONE);
1259bf215546Sopenharmony_ci      unsigned fs_ver = get_uint_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION,
1260bf215546Sopenharmony_ci                                     SVGA3DPSVERSION_NONE);
1261bf215546Sopenharmony_ci
1262bf215546Sopenharmony_ci      /* we require Shader model 3.0 or later */
1263bf215546Sopenharmony_ci      if (fs_ver < SVGA3DPSVERSION_30 || vs_ver < SVGA3DVSVERSION_30) {
1264bf215546Sopenharmony_ci         goto error2;
1265bf215546Sopenharmony_ci      }
1266bf215546Sopenharmony_ci
1267bf215546Sopenharmony_ci      svgascreen->haveProvokingVertex = FALSE;
1268bf215546Sopenharmony_ci
1269bf215546Sopenharmony_ci      svgascreen->haveLineSmooth =
1270bf215546Sopenharmony_ci         get_bool_cap(sws, SVGA3D_DEVCAP_LINE_AA, FALSE);
1271bf215546Sopenharmony_ci
1272bf215546Sopenharmony_ci      svgascreen->maxPointSize =
1273bf215546Sopenharmony_ci         get_float_cap(sws, SVGA3D_DEVCAP_MAX_POINT_SIZE, 1.0f);
1274bf215546Sopenharmony_ci      /* Keep this to a reasonable size to avoid failures in conform/pntaa.c */
1275bf215546Sopenharmony_ci      svgascreen->maxPointSize = MIN2(svgascreen->maxPointSize, 80.0f);
1276bf215546Sopenharmony_ci
1277bf215546Sopenharmony_ci      /* The SVGA3D device always supports 4 targets at this time, regardless
1278bf215546Sopenharmony_ci       * of what querying SVGA3D_DEVCAP_MAX_RENDER_TARGETS might return.
1279bf215546Sopenharmony_ci       */
1280bf215546Sopenharmony_ci      svgascreen->max_color_buffers = 4;
1281bf215546Sopenharmony_ci
1282bf215546Sopenharmony_ci      /* Only support one constant buffer
1283bf215546Sopenharmony_ci       */
1284bf215546Sopenharmony_ci      svgascreen->max_const_buffers = 1;
1285bf215546Sopenharmony_ci
1286bf215546Sopenharmony_ci      /* No multisampling */
1287bf215546Sopenharmony_ci      svgascreen->ms_samples = 0;
1288bf215546Sopenharmony_ci
1289bf215546Sopenharmony_ci      /* Only one viewport */
1290bf215546Sopenharmony_ci      svgascreen->max_viewports = 1;
1291bf215546Sopenharmony_ci
1292bf215546Sopenharmony_ci      /* Shader limits */
1293bf215546Sopenharmony_ci      svgascreen->max_vs_inputs  = 16;
1294bf215546Sopenharmony_ci      svgascreen->max_vs_outputs = 10;
1295bf215546Sopenharmony_ci      svgascreen->max_gs_inputs  = 0;
1296bf215546Sopenharmony_ci   }
1297bf215546Sopenharmony_ci
1298bf215546Sopenharmony_ci   /* common VGPU9 / VGPU10 caps */
1299bf215546Sopenharmony_ci   svgascreen->haveLineStipple =
1300bf215546Sopenharmony_ci      get_bool_cap(sws, SVGA3D_DEVCAP_LINE_STIPPLE, FALSE);
1301bf215546Sopenharmony_ci
1302bf215546Sopenharmony_ci   svgascreen->maxLineWidth =
1303bf215546Sopenharmony_ci      MAX2(1.0, get_float_cap(sws, SVGA3D_DEVCAP_MAX_LINE_WIDTH, 1.0f));
1304bf215546Sopenharmony_ci
1305bf215546Sopenharmony_ci   svgascreen->maxLineWidthAA =
1306bf215546Sopenharmony_ci      MAX2(1.0, get_float_cap(sws, SVGA3D_DEVCAP_MAX_AA_LINE_WIDTH, 1.0f));
1307bf215546Sopenharmony_ci
1308bf215546Sopenharmony_ci   if (0) {
1309bf215546Sopenharmony_ci      debug_printf("svga: haveProvokingVertex %u\n",
1310bf215546Sopenharmony_ci                   svgascreen->haveProvokingVertex);
1311bf215546Sopenharmony_ci      debug_printf("svga: haveLineStip %u  "
1312bf215546Sopenharmony_ci                   "haveLineSmooth %u  maxLineWidth %.2f  maxLineWidthAA %.2f\n",
1313bf215546Sopenharmony_ci                   svgascreen->haveLineStipple, svgascreen->haveLineSmooth,
1314bf215546Sopenharmony_ci                   svgascreen->maxLineWidth, svgascreen->maxLineWidthAA);
1315bf215546Sopenharmony_ci      debug_printf("svga: maxPointSize %g\n", svgascreen->maxPointSize);
1316bf215546Sopenharmony_ci      debug_printf("svga: msaa samples mask: 0x%x\n", svgascreen->ms_samples);
1317bf215546Sopenharmony_ci   }
1318bf215546Sopenharmony_ci
1319bf215546Sopenharmony_ci   (void) mtx_init(&svgascreen->tex_mutex, mtx_plain);
1320bf215546Sopenharmony_ci   (void) mtx_init(&svgascreen->swc_mutex, mtx_recursive);
1321bf215546Sopenharmony_ci
1322bf215546Sopenharmony_ci   svga_screen_cache_init(svgascreen);
1323bf215546Sopenharmony_ci
1324bf215546Sopenharmony_ci   if (debug_get_bool_option("SVGA_NO_LOGGING", FALSE) == TRUE) {
1325bf215546Sopenharmony_ci      svgascreen->sws->host_log = nop_host_log;
1326bf215546Sopenharmony_ci   } else {
1327bf215546Sopenharmony_ci      init_logging(screen);
1328bf215546Sopenharmony_ci   }
1329bf215546Sopenharmony_ci
1330bf215546Sopenharmony_ci   return screen;
1331bf215546Sopenharmony_cierror2:
1332bf215546Sopenharmony_ci   FREE(svgascreen);
1333bf215546Sopenharmony_cierror1:
1334bf215546Sopenharmony_ci   return NULL;
1335bf215546Sopenharmony_ci}
1336bf215546Sopenharmony_ci
1337bf215546Sopenharmony_ci
1338bf215546Sopenharmony_cistruct svga_winsys_screen *
1339bf215546Sopenharmony_cisvga_winsys_screen(struct pipe_screen *screen)
1340bf215546Sopenharmony_ci{
1341bf215546Sopenharmony_ci   return svga_screen(screen)->sws;
1342bf215546Sopenharmony_ci}
1343bf215546Sopenharmony_ci
1344bf215546Sopenharmony_ci
1345bf215546Sopenharmony_ci#ifdef DEBUG
1346bf215546Sopenharmony_cistruct svga_screen *
1347bf215546Sopenharmony_cisvga_screen(struct pipe_screen *screen)
1348bf215546Sopenharmony_ci{
1349bf215546Sopenharmony_ci   assert(screen);
1350bf215546Sopenharmony_ci   assert(screen->destroy == svga_destroy_screen);
1351bf215546Sopenharmony_ci   return (struct svga_screen *)screen;
1352bf215546Sopenharmony_ci}
1353bf215546Sopenharmony_ci#endif
1354