1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "compiler/nir/nir.h"
29 #include "draw/draw_context.h"
30 #include "util/format/u_format.h"
31 #include "util/format/u_format_s3tc.h"
32 #include "util/os_misc.h"
33 #include "util/u_inlines.h"
34 #include "util/u_memory.h"
35 #include "util/u_screen.h"
36 #include "util/u_string.h"
37
38 #include "i915_context.h"
39 #include "i915_debug.h"
40 #include "i915_public.h"
41 #include "i915_reg.h"
42 #include "i915_resource.h"
43 #include "i915_screen.h"
44 #include "i915_winsys.h"
45
46 /*
47 * Probe functions
48 */
49
50 static const char *
i915_get_vendor(struct pipe_screen * screen)51 i915_get_vendor(struct pipe_screen *screen)
52 {
53 return "Mesa Project";
54 }
55
56 static const char *
i915_get_device_vendor(struct pipe_screen * screen)57 i915_get_device_vendor(struct pipe_screen *screen)
58 {
59 return "Intel";
60 }
61
62 static const char *
i915_get_name(struct pipe_screen * screen)63 i915_get_name(struct pipe_screen *screen)
64 {
65 static char buffer[128];
66 const char *chipset;
67
68 switch (i915_screen(screen)->iws->pci_id) {
69 case PCI_CHIP_I915_G:
70 chipset = "915G";
71 break;
72 case PCI_CHIP_I915_GM:
73 chipset = "915GM";
74 break;
75 case PCI_CHIP_I945_G:
76 chipset = "945G";
77 break;
78 case PCI_CHIP_I945_GM:
79 chipset = "945GM";
80 break;
81 case PCI_CHIP_I945_GME:
82 chipset = "945GME";
83 break;
84 case PCI_CHIP_G33_G:
85 chipset = "G33";
86 break;
87 case PCI_CHIP_Q35_G:
88 chipset = "Q35";
89 break;
90 case PCI_CHIP_Q33_G:
91 chipset = "Q33";
92 break;
93 case PCI_CHIP_PINEVIEW_G:
94 chipset = "Pineview G";
95 break;
96 case PCI_CHIP_PINEVIEW_M:
97 chipset = "Pineview M";
98 break;
99 default:
100 chipset = "unknown";
101 break;
102 }
103
104 snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset);
105 return buffer;
106 }
107
108 static const nir_shader_compiler_options i915_compiler_options = {
109 .fdot_replicates = true,
110 .fuse_ffma32 = true,
111 .lower_bitops = true, /* required for !CAP_INTEGERS nir_to_tgsi */
112 .lower_extract_byte = true,
113 .lower_extract_word = true,
114 .lower_fdiv = true,
115 .lower_fdph = true,
116 .lower_flrp32 = true,
117 .lower_fmod = true,
118 .lower_rotate = true,
119 .lower_sincos = true,
120 .lower_uniforms_to_ubo = true,
121 .lower_vector_cmp = true,
122 .use_interpolated_input_intrinsics = true,
123 .force_indirect_unrolling = nir_var_all,
124 .force_indirect_unrolling_sampler = true,
125 .max_unroll_iterations = 32,
126 .no_integers = true,
127 };
128
129 static const struct nir_shader_compiler_options gallivm_nir_options = {
130 .fdot_replicates = true,
131 .lower_bitops = true, /* required for !CAP_INTEGERS nir_to_tgsi */
132 .lower_scmp = true,
133 .lower_flrp32 = true,
134 .lower_flrp64 = true,
135 .lower_fsat = true,
136 .lower_bitfield_insert_to_shifts = true,
137 .lower_bitfield_extract_to_shifts = true,
138 .lower_fdph = true,
139 .lower_ffma16 = true,
140 .lower_ffma32 = true,
141 .lower_ffma64 = true,
142 .lower_fmod = true,
143 .lower_hadd = true,
144 .lower_uadd_sat = true,
145 .lower_usub_sat = true,
146 .lower_iadd_sat = true,
147 .lower_ldexp = true,
148 .lower_pack_snorm_2x16 = true,
149 .lower_pack_snorm_4x8 = true,
150 .lower_pack_unorm_2x16 = true,
151 .lower_pack_unorm_4x8 = true,
152 .lower_pack_half_2x16 = true,
153 .lower_pack_split = true,
154 .lower_unpack_snorm_2x16 = true,
155 .lower_unpack_snorm_4x8 = true,
156 .lower_unpack_unorm_2x16 = true,
157 .lower_unpack_unorm_4x8 = true,
158 .lower_unpack_half_2x16 = true,
159 .lower_extract_byte = true,
160 .lower_extract_word = true,
161 .lower_rotate = true,
162 .lower_uadd_carry = true,
163 .lower_usub_borrow = true,
164 .lower_mul_2x32_64 = true,
165 .lower_ifind_msb = true,
166 .max_unroll_iterations = 32,
167 .use_interpolated_input_intrinsics = true,
168 .lower_cs_local_index_to_id = true,
169 .lower_uniforms_to_ubo = true,
170 .lower_vector_cmp = true,
171 .lower_device_index_to_zero = true,
172 /* .support_16bit_alu = true, */
173 };
174
175 static const void *
i915_get_compiler_options(struct pipe_screen * pscreen,enum pipe_shader_ir ir,enum pipe_shader_type shader)176 i915_get_compiler_options(struct pipe_screen *pscreen, enum pipe_shader_ir ir,
177 enum pipe_shader_type shader)
178 {
179 assert(ir == PIPE_SHADER_IR_NIR);
180 if (shader == PIPE_SHADER_FRAGMENT)
181 return &i915_compiler_options;
182 else
183 return &gallivm_nir_options;
184 }
185
186 static void
i915_optimize_nir(struct nir_shader * s)187 i915_optimize_nir(struct nir_shader *s)
188 {
189 bool progress;
190
191 do {
192 progress = false;
193
194 NIR_PASS_V(s, nir_lower_vars_to_ssa);
195
196 NIR_PASS(progress, s, nir_copy_prop);
197 NIR_PASS(progress, s, nir_opt_algebraic);
198 NIR_PASS(progress, s, nir_opt_constant_folding);
199 NIR_PASS(progress, s, nir_opt_remove_phis);
200 NIR_PASS(progress, s, nir_opt_conditional_discard);
201 NIR_PASS(progress, s, nir_opt_dce);
202 NIR_PASS(progress, s, nir_opt_dead_cf);
203 NIR_PASS(progress, s, nir_opt_cse);
204 NIR_PASS(progress, s, nir_opt_find_array_copies);
205 NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
206 NIR_PASS(progress, s, nir_opt_peephole_select, ~0 /* flatten all IFs. */,
207 true, true);
208 NIR_PASS(progress, s, nir_opt_algebraic);
209 NIR_PASS(progress, s, nir_opt_constant_folding);
210 NIR_PASS(progress, s, nir_opt_shrink_stores, true);
211 NIR_PASS(progress, s, nir_opt_shrink_vectors);
212 NIR_PASS(progress, s, nir_opt_trivial_continues);
213 NIR_PASS(progress, s, nir_opt_undef);
214 NIR_PASS(progress, s, nir_opt_loop_unroll);
215
216 } while (progress);
217
218 NIR_PASS(progress, s, nir_remove_dead_variables, nir_var_function_temp,
219 NULL);
220 }
221
i915_check_control_flow(nir_shader * s)222 static char *i915_check_control_flow(nir_shader *s)
223 {
224 if (s->info.stage == MESA_SHADER_FRAGMENT) {
225 nir_function_impl *impl = nir_shader_get_entrypoint(s);
226 nir_block *first = nir_start_block(impl);
227 nir_cf_node *next = nir_cf_node_next(&first->cf_node);
228
229 if (next) {
230 switch (next->type) {
231 case nir_cf_node_if:
232 return "if/then statements not supported by i915 fragment shaders, should have been flattened by peephole_select.";
233 case nir_cf_node_loop:
234 return "looping not supported i915 fragment shaders, all loops must be statically unrollable.";
235 default:
236 return "Unknown control flow type";
237 }
238 }
239 }
240
241 return NULL;
242 }
243
244 static char *
i915_finalize_nir(struct pipe_screen * pscreen,void * nir)245 i915_finalize_nir(struct pipe_screen *pscreen, void *nir)
246 {
247 nir_shader *s = nir;
248
249 if (s->info.stage == MESA_SHADER_FRAGMENT)
250 i915_optimize_nir(s);
251
252 /* st_program.c's parameter list optimization requires that future nir
253 * variants don't reallocate the uniform storage, so we have to remove
254 * uniforms that occupy storage. But we don't want to remove samplers,
255 * because they're needed for YUV variant lowering.
256 */
257 nir_remove_dead_derefs(s);
258 nir_foreach_uniform_variable_safe(var, s)
259 {
260 if (var->data.mode == nir_var_uniform &&
261 (glsl_type_get_image_count(var->type) ||
262 glsl_type_get_sampler_count(var->type)))
263 continue;
264
265 exec_node_remove(&var->node);
266 }
267 nir_validate_shader(s, "after uniform var removal");
268
269 nir_sweep(s);
270
271 char *msg = i915_check_control_flow(s);
272 if (msg)
273 return strdup(msg);
274
275 return NULL;
276 }
277
278 static int
i915_get_shader_param(struct pipe_screen * screen,enum pipe_shader_type shader,enum pipe_shader_cap cap)279 i915_get_shader_param(struct pipe_screen *screen, enum pipe_shader_type shader,
280 enum pipe_shader_cap cap)
281 {
282 switch (cap) {
283 case PIPE_SHADER_CAP_PREFERRED_IR:
284 return PIPE_SHADER_IR_NIR;
285 case PIPE_SHADER_CAP_SUPPORTED_IRS:
286 return (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_TGSI);
287
288 case PIPE_SHADER_CAP_INTEGERS:
289 /* mesa/st requires that this cap is the same across stages, and the FS
290 * can't do ints.
291 */
292 return 0;
293
294 /* i915 can't do these, and even if gallivm NIR can we call nir_to_tgsi
295 * manually and TGSI can't.
296 */
297 case PIPE_SHADER_CAP_INT16:
298 case PIPE_SHADER_CAP_FP16:
299 case PIPE_SHADER_CAP_FP16_DERIVATIVES:
300 case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
301 return 0;
302
303 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
304 /* While draw could normally handle this for the VS, the NIR lowering
305 * to regs can't handle our non-native-integers, so we have to lower to
306 * if ladders.
307 */
308 return 0;
309
310 default:
311 break;
312 }
313
314 switch (shader) {
315 case PIPE_SHADER_VERTEX:
316 switch (cap) {
317 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
318 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
319 return 0;
320 case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
321 case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
322 return 0;
323 default:
324 return draw_get_shader_param(shader, cap);
325 }
326 case PIPE_SHADER_FRAGMENT:
327 /* XXX: some of these are just shader model 2.0 values, fix this! */
328 switch (cap) {
329 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
330 return I915_MAX_ALU_INSN + I915_MAX_TEX_INSN;
331 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
332 return I915_MAX_ALU_INSN;
333 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
334 return I915_MAX_TEX_INSN;
335 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
336 return 4;
337 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
338 return 0;
339 case PIPE_SHADER_CAP_MAX_INPUTS:
340 return 10;
341 case PIPE_SHADER_CAP_MAX_OUTPUTS:
342 return 1;
343 case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
344 return 32 * sizeof(float[4]);
345 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
346 return 1;
347 case PIPE_SHADER_CAP_MAX_TEMPS:
348 /* 16 inter-phase temps, 3 intra-phase temps. i915c reported 16. too. */
349 return 16;
350 case PIPE_SHADER_CAP_CONT_SUPPORTED:
351 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
352 return 0;
353 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
354 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
355 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
356 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
357 case PIPE_SHADER_CAP_SUBROUTINES:
358 return 0;
359 case PIPE_SHADER_CAP_INT64_ATOMICS:
360 case PIPE_SHADER_CAP_INT16:
361 case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
362 return 0;
363 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
364 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
365 return I915_TEX_UNITS;
366 case PIPE_SHADER_CAP_DROUND_SUPPORTED:
367 case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
368 case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
369 case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
370 case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
371 case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
372 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
373 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
374 return 0;
375
376 default:
377 debug_printf("%s: Unknown cap %u.\n", __FUNCTION__, cap);
378 return 0;
379 }
380 break;
381 default:
382 return 0;
383 }
384 }
385
386 static int
i915_get_param(struct pipe_screen * screen,enum pipe_cap cap)387 i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
388 {
389 struct i915_screen *is = i915_screen(screen);
390
391 switch (cap) {
392 /* Supported features (boolean caps). */
393 case PIPE_CAP_ANISOTROPIC_FILTER:
394 case PIPE_CAP_NPOT_TEXTURES:
395 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
396 case PIPE_CAP_POINT_SPRITE:
397 case PIPE_CAP_PRIMITIVE_RESTART: /* draw module */
398 case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
399 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
400 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
401 case PIPE_CAP_VS_INSTANCEID:
402 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
403 case PIPE_CAP_USER_VERTEX_BUFFERS:
404 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
405 case PIPE_CAP_TGSI_TEXCOORD:
406 return 1;
407
408 case PIPE_CAP_TEXTURE_TRANSFER_MODES:
409 case PIPE_CAP_PCI_GROUP:
410 case PIPE_CAP_PCI_BUS:
411 case PIPE_CAP_PCI_DEVICE:
412 case PIPE_CAP_PCI_FUNCTION:
413 return 0;
414
415 case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
416 return 0;
417
418 case PIPE_CAP_SHAREABLE_SHADERS:
419 /* Can't expose shareable shaders because the draw shaders reference the
420 * draw module's state, which is per-context.
421 */
422 return 0;
423
424 case PIPE_CAP_MAX_GS_INVOCATIONS:
425 return 32;
426
427 case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
428 return 1 << 27;
429
430 case PIPE_CAP_MAX_VIEWPORTS:
431 return 1;
432
433 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
434 return 64;
435
436 case PIPE_CAP_GLSL_FEATURE_LEVEL:
437 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
438 return 120;
439
440 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
441 return 16;
442
443 /* Texturing. */
444 case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
445 return 1 << (I915_MAX_TEXTURE_2D_LEVELS - 1);
446 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
447 return I915_MAX_TEXTURE_3D_LEVELS;
448 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
449 return 1 << (I915_MAX_TEXTURE_2D_LEVELS - 1);
450
451 /* Render targets. */
452 case PIPE_CAP_MAX_RENDER_TARGETS:
453 return 1;
454
455 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
456 return 2048;
457
458 /* Fragment coordinate conventions. */
459 case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
460 case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
461 return 1;
462 case PIPE_CAP_ENDIANNESS:
463 return PIPE_ENDIAN_LITTLE;
464 case PIPE_CAP_MAX_VARYINGS:
465 return 10;
466
467 case PIPE_CAP_NIR_IMAGES_AS_DEREF:
468 return 0;
469
470 case PIPE_CAP_VENDOR_ID:
471 return 0x8086;
472 case PIPE_CAP_DEVICE_ID:
473 return is->iws->pci_id;
474 case PIPE_CAP_ACCELERATED:
475 return 1;
476 case PIPE_CAP_VIDEO_MEMORY: {
477 /* Once a batch uses more than 75% of the maximum mappable size, we
478 * assume that there's some fragmentation, and we start doing extra
479 * flushing, etc. That's the big cliff apps will care about.
480 */
481 const int gpu_mappable_megabytes =
482 is->iws->aperture_size(is->iws) * 3 / 4;
483 uint64_t system_memory;
484
485 if (!os_get_total_physical_memory(&system_memory))
486 return 0;
487
488 return MIN2(gpu_mappable_megabytes, (int)(system_memory >> 20));
489 }
490 case PIPE_CAP_UMA:
491 return 1;
492
493 default:
494 return u_pipe_screen_get_param_defaults(screen, cap);
495 }
496 }
497
498 static float
i915_get_paramf(struct pipe_screen * screen,enum pipe_capf cap)499 i915_get_paramf(struct pipe_screen *screen, enum pipe_capf cap)
500 {
501 switch (cap) {
502 case PIPE_CAPF_MIN_LINE_WIDTH:
503 case PIPE_CAPF_MIN_LINE_WIDTH_AA:
504 case PIPE_CAPF_MIN_POINT_SIZE:
505 case PIPE_CAPF_MIN_POINT_SIZE_AA:
506 return 1;
507
508 case PIPE_CAPF_POINT_SIZE_GRANULARITY:
509 case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
510 return 0.1;
511
512 case PIPE_CAPF_MAX_LINE_WIDTH:
513 FALLTHROUGH;
514 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
515 return 7.5;
516
517 case PIPE_CAPF_MAX_POINT_SIZE:
518 FALLTHROUGH;
519 case PIPE_CAPF_MAX_POINT_SIZE_AA:
520 return 255.0;
521
522 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
523 return 4.0;
524
525 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
526 return 16.0;
527
528 case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
529 FALLTHROUGH;
530 case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
531 FALLTHROUGH;
532 case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
533 return 0.0f;
534
535 default:
536 debug_printf("%s: Unknown cap %u.\n", __FUNCTION__, cap);
537 return 0;
538 }
539 }
540
541 bool
i915_is_format_supported(struct pipe_screen * screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned tex_usage)542 i915_is_format_supported(struct pipe_screen *screen, enum pipe_format format,
543 enum pipe_texture_target target, unsigned sample_count,
544 unsigned storage_sample_count, unsigned tex_usage)
545 {
546 static const enum pipe_format tex_supported[] = {
547 PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_FORMAT_B8G8R8A8_SRGB,
548 PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_FORMAT_R8G8B8A8_UNORM,
549 PIPE_FORMAT_R8G8B8X8_UNORM, PIPE_FORMAT_B4G4R4A4_UNORM,
550 PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_B5G5R5A1_UNORM,
551 PIPE_FORMAT_B10G10R10A2_UNORM, PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_A8_UNORM,
552 PIPE_FORMAT_I8_UNORM, PIPE_FORMAT_L8A8_UNORM, PIPE_FORMAT_UYVY,
553 PIPE_FORMAT_YUYV,
554 /* XXX why not?
555 PIPE_FORMAT_Z16_UNORM, */
556 PIPE_FORMAT_DXT1_RGB, PIPE_FORMAT_DXT1_SRGB, PIPE_FORMAT_DXT1_RGBA,
557 PIPE_FORMAT_DXT1_SRGBA, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT3_SRGBA,
558 PIPE_FORMAT_DXT5_RGBA, PIPE_FORMAT_DXT5_SRGBA, PIPE_FORMAT_Z24X8_UNORM,
559 PIPE_FORMAT_FXT1_RGB, PIPE_FORMAT_FXT1_RGBA,
560 PIPE_FORMAT_Z24_UNORM_S8_UINT, PIPE_FORMAT_NONE /* list terminator */
561 };
562 static const enum pipe_format render_supported[] = {
563 PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_FORMAT_B8G8R8X8_UNORM,
564 PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_R8G8B8X8_UNORM,
565 PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_B5G5R5A1_UNORM,
566 PIPE_FORMAT_B4G4R4A4_UNORM, PIPE_FORMAT_B10G10R10A2_UNORM,
567 PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_A8_UNORM,
568 PIPE_FORMAT_I8_UNORM, PIPE_FORMAT_NONE /* list terminator */
569 };
570 static const enum pipe_format depth_supported[] = {
571 /* XXX why not?
572 PIPE_FORMAT_Z16_UNORM, */
573 PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_Z24_UNORM_S8_UINT,
574 PIPE_FORMAT_NONE /* list terminator */
575 };
576 const enum pipe_format *list;
577 uint32_t i;
578
579 if (sample_count > 1)
580 return false;
581
582 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
583 return false;
584
585 if (tex_usage & PIPE_BIND_DEPTH_STENCIL)
586 list = depth_supported;
587 else if (tex_usage & PIPE_BIND_RENDER_TARGET)
588 list = render_supported;
589 else if (tex_usage & PIPE_BIND_SAMPLER_VIEW)
590 list = tex_supported;
591 else
592 return true; /* PIPE_BIND_{VERTEX,INDEX}_BUFFER */
593
594 for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) {
595 if (list[i] == format)
596 return true;
597 }
598
599 return false;
600 }
601
602 /*
603 * Fence functions
604 */
605
606 static void
i915_fence_reference(struct pipe_screen * screen,struct pipe_fence_handle ** ptr,struct pipe_fence_handle * fence)607 i915_fence_reference(struct pipe_screen *screen, struct pipe_fence_handle **ptr,
608 struct pipe_fence_handle *fence)
609 {
610 struct i915_screen *is = i915_screen(screen);
611
612 is->iws->fence_reference(is->iws, ptr, fence);
613 }
614
615 static bool
i915_fence_finish(struct pipe_screen * screen,struct pipe_context * ctx,struct pipe_fence_handle * fence,uint64_t timeout)616 i915_fence_finish(struct pipe_screen *screen, struct pipe_context *ctx,
617 struct pipe_fence_handle *fence, uint64_t timeout)
618 {
619 struct i915_screen *is = i915_screen(screen);
620
621 if (!timeout)
622 return is->iws->fence_signalled(is->iws, fence) == 1;
623
624 return is->iws->fence_finish(is->iws, fence) == 1;
625 }
626
627 /*
628 * Generic functions
629 */
630
631 static void
i915_destroy_screen(struct pipe_screen * screen)632 i915_destroy_screen(struct pipe_screen *screen)
633 {
634 struct i915_screen *is = i915_screen(screen);
635
636 if (is->iws)
637 is->iws->destroy(is->iws);
638
639 FREE(is);
640 }
641
642 /**
643 * Create a new i915_screen object
644 */
645 struct pipe_screen *
i915_screen_create(struct i915_winsys * iws)646 i915_screen_create(struct i915_winsys *iws)
647 {
648 struct i915_screen *is = CALLOC_STRUCT(i915_screen);
649
650 if (!is)
651 return NULL;
652
653 switch (iws->pci_id) {
654 case PCI_CHIP_I915_G:
655 case PCI_CHIP_I915_GM:
656 is->is_i945 = false;
657 break;
658
659 case PCI_CHIP_I945_G:
660 case PCI_CHIP_I945_GM:
661 case PCI_CHIP_I945_GME:
662 case PCI_CHIP_G33_G:
663 case PCI_CHIP_Q33_G:
664 case PCI_CHIP_Q35_G:
665 case PCI_CHIP_PINEVIEW_G:
666 case PCI_CHIP_PINEVIEW_M:
667 is->is_i945 = true;
668 break;
669
670 default:
671 debug_printf("%s: unknown pci id 0x%x, cannot create screen\n",
672 __FUNCTION__, iws->pci_id);
673 FREE(is);
674 return NULL;
675 }
676
677 is->iws = iws;
678
679 is->base.destroy = i915_destroy_screen;
680
681 is->base.get_name = i915_get_name;
682 is->base.get_vendor = i915_get_vendor;
683 is->base.get_device_vendor = i915_get_device_vendor;
684 is->base.get_param = i915_get_param;
685 is->base.get_shader_param = i915_get_shader_param;
686 is->base.get_paramf = i915_get_paramf;
687 is->base.get_compiler_options = i915_get_compiler_options;
688 is->base.finalize_nir = i915_finalize_nir;
689 is->base.is_format_supported = i915_is_format_supported;
690
691 is->base.context_create = i915_create_context;
692
693 is->base.fence_reference = i915_fence_reference;
694 is->base.fence_finish = i915_fence_finish;
695
696 i915_init_screen_resource_functions(is);
697
698 i915_debug_init(is);
699
700 return &is->base;
701 }
702