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