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 "brw_clip.h"
25
26 #include "common/gen_debug.h"
27
28 const unsigned *
brw_compile_clip(const struct brw_compiler * compiler,void * mem_ctx,const struct brw_clip_prog_key * key,struct brw_clip_prog_data * prog_data,struct brw_vue_map * vue_map,unsigned * final_assembly_size)29 brw_compile_clip(const struct brw_compiler *compiler,
30 void *mem_ctx,
31 const struct brw_clip_prog_key *key,
32 struct brw_clip_prog_data *prog_data,
33 struct brw_vue_map *vue_map,
34 unsigned *final_assembly_size)
35 {
36 struct brw_clip_compile c;
37 memset(&c, 0, sizeof(c));
38
39 /* Begin the compilation:
40 */
41 brw_init_codegen(compiler->devinfo, &c.func, mem_ctx);
42
43 c.func.single_program_flow = 1;
44
45 c.key = *key;
46 c.vue_map = *vue_map;
47
48 /* nr_regs is the number of registers filled by reading data from the VUE.
49 * This program accesses the entire VUE, so nr_regs needs to be the size of
50 * the VUE (measured in pairs, since two slots are stored in each
51 * register).
52 */
53 c.nr_regs = (c.vue_map.num_slots + 1)/2;
54
55 c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
56
57 /* For some reason the thread is spawned with only 4 channels
58 * unmasked.
59 */
60 brw_set_default_mask_control(&c.func, BRW_MASK_DISABLE);
61
62 /* Would ideally have the option of producing a program which could
63 * do all three:
64 */
65 switch (key->primitive) {
66 case GL_TRIANGLES:
67 if (key->do_unfilled)
68 brw_emit_unfilled_clip( &c );
69 else
70 brw_emit_tri_clip( &c );
71 break;
72 case GL_LINES:
73 brw_emit_line_clip( &c );
74 break;
75 case GL_POINTS:
76 brw_emit_point_clip( &c );
77 break;
78 default:
79 unreachable("not reached");
80 }
81
82 brw_compact_instructions(&c.func, 0, NULL);
83
84 *prog_data = c.prog_data;
85
86 const unsigned *program = brw_get_program(&c.func, final_assembly_size);
87
88 if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) {
89 fprintf(stderr, "clip:\n");
90 brw_disassemble(compiler->devinfo,
91 program, 0, *final_assembly_size, stderr);
92 fprintf(stderr, "\n");
93 }
94
95 return program;
96 }
97