1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2006 - 2017 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include "brw_clip.h"
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "dev/intel_debug.h"
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ciconst unsigned *
29bf215546Sopenharmony_cibrw_compile_clip(const struct brw_compiler *compiler,
30bf215546Sopenharmony_ci                 void *mem_ctx,
31bf215546Sopenharmony_ci                 const struct brw_clip_prog_key *key,
32bf215546Sopenharmony_ci                 struct brw_clip_prog_data *prog_data,
33bf215546Sopenharmony_ci                 struct brw_vue_map *vue_map,
34bf215546Sopenharmony_ci                 unsigned *final_assembly_size)
35bf215546Sopenharmony_ci{
36bf215546Sopenharmony_ci   struct brw_clip_compile c;
37bf215546Sopenharmony_ci   memset(&c, 0, sizeof(c));
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci   /* Begin the compilation:
40bf215546Sopenharmony_ci    */
41bf215546Sopenharmony_ci   brw_init_codegen(&compiler->isa, &c.func, mem_ctx);
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci   c.func.single_program_flow = 1;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   c.key = *key;
46bf215546Sopenharmony_ci   c.vue_map = *vue_map;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   /* nr_regs is the number of registers filled by reading data from the VUE.
49bf215546Sopenharmony_ci    * This program accesses the entire VUE, so nr_regs needs to be the size of
50bf215546Sopenharmony_ci    * the VUE (measured in pairs, since two slots are stored in each
51bf215546Sopenharmony_ci    * register).
52bf215546Sopenharmony_ci    */
53bf215546Sopenharmony_ci   c.nr_regs = (c.vue_map.num_slots + 1)/2;
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   /* For some reason the thread is spawned with only 4 channels
58bf215546Sopenharmony_ci    * unmasked.
59bf215546Sopenharmony_ci    */
60bf215546Sopenharmony_ci   brw_set_default_mask_control(&c.func, BRW_MASK_DISABLE);
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   /* Would ideally have the option of producing a program which could
63bf215546Sopenharmony_ci    * do all three:
64bf215546Sopenharmony_ci    */
65bf215546Sopenharmony_ci   switch (key->primitive) {
66bf215546Sopenharmony_ci   case SHADER_PRIM_TRIANGLES:
67bf215546Sopenharmony_ci      if (key->do_unfilled)
68bf215546Sopenharmony_ci	 brw_emit_unfilled_clip( &c );
69bf215546Sopenharmony_ci      else
70bf215546Sopenharmony_ci	 brw_emit_tri_clip( &c );
71bf215546Sopenharmony_ci      break;
72bf215546Sopenharmony_ci   case SHADER_PRIM_LINES:
73bf215546Sopenharmony_ci      brw_emit_line_clip( &c );
74bf215546Sopenharmony_ci      break;
75bf215546Sopenharmony_ci   case SHADER_PRIM_POINTS:
76bf215546Sopenharmony_ci      brw_emit_point_clip( &c );
77bf215546Sopenharmony_ci      break;
78bf215546Sopenharmony_ci   default:
79bf215546Sopenharmony_ci      unreachable("not reached");
80bf215546Sopenharmony_ci   }
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci   brw_compact_instructions(&c.func, 0, NULL);
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   *prog_data = c.prog_data;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   const unsigned *program = brw_get_program(&c.func, final_assembly_size);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   if (INTEL_DEBUG(DEBUG_CLIP)) {
89bf215546Sopenharmony_ci      fprintf(stderr, "clip:\n");
90bf215546Sopenharmony_ci      brw_disassemble_with_labels(&compiler->isa,
91bf215546Sopenharmony_ci                                  program, 0, *final_assembly_size, stderr);
92bf215546Sopenharmony_ci      fprintf(stderr, "\n");
93bf215546Sopenharmony_ci   }
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   return program;
96bf215546Sopenharmony_ci}
97