101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2006 - 2017 Intel Corporation
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
901e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2101e04c3fSmrg * IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg#include "brw_clip.h"
2501e04c3fSmrg
267ec681f3Smrg#include "dev/intel_debug.h"
2701e04c3fSmrg
2801e04c3fSmrgconst unsigned *
2901e04c3fSmrgbrw_compile_clip(const struct brw_compiler *compiler,
3001e04c3fSmrg                 void *mem_ctx,
3101e04c3fSmrg                 const struct brw_clip_prog_key *key,
3201e04c3fSmrg                 struct brw_clip_prog_data *prog_data,
3301e04c3fSmrg                 struct brw_vue_map *vue_map,
3401e04c3fSmrg                 unsigned *final_assembly_size)
3501e04c3fSmrg{
3601e04c3fSmrg   struct brw_clip_compile c;
3701e04c3fSmrg   memset(&c, 0, sizeof(c));
3801e04c3fSmrg
3901e04c3fSmrg   /* Begin the compilation:
4001e04c3fSmrg    */
4101e04c3fSmrg   brw_init_codegen(compiler->devinfo, &c.func, mem_ctx);
4201e04c3fSmrg
4301e04c3fSmrg   c.func.single_program_flow = 1;
4401e04c3fSmrg
4501e04c3fSmrg   c.key = *key;
4601e04c3fSmrg   c.vue_map = *vue_map;
4701e04c3fSmrg
4801e04c3fSmrg   /* nr_regs is the number of registers filled by reading data from the VUE.
4901e04c3fSmrg    * This program accesses the entire VUE, so nr_regs needs to be the size of
5001e04c3fSmrg    * the VUE (measured in pairs, since two slots are stored in each
5101e04c3fSmrg    * register).
5201e04c3fSmrg    */
5301e04c3fSmrg   c.nr_regs = (c.vue_map.num_slots + 1)/2;
5401e04c3fSmrg
5501e04c3fSmrg   c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
5601e04c3fSmrg
5701e04c3fSmrg   /* For some reason the thread is spawned with only 4 channels
5801e04c3fSmrg    * unmasked.
5901e04c3fSmrg    */
6001e04c3fSmrg   brw_set_default_mask_control(&c.func, BRW_MASK_DISABLE);
6101e04c3fSmrg
6201e04c3fSmrg   /* Would ideally have the option of producing a program which could
6301e04c3fSmrg    * do all three:
6401e04c3fSmrg    */
6501e04c3fSmrg   switch (key->primitive) {
6601e04c3fSmrg   case GL_TRIANGLES:
6701e04c3fSmrg      if (key->do_unfilled)
6801e04c3fSmrg	 brw_emit_unfilled_clip( &c );
6901e04c3fSmrg      else
7001e04c3fSmrg	 brw_emit_tri_clip( &c );
7101e04c3fSmrg      break;
7201e04c3fSmrg   case GL_LINES:
7301e04c3fSmrg      brw_emit_line_clip( &c );
7401e04c3fSmrg      break;
7501e04c3fSmrg   case GL_POINTS:
7601e04c3fSmrg      brw_emit_point_clip( &c );
7701e04c3fSmrg      break;
7801e04c3fSmrg   default:
7901e04c3fSmrg      unreachable("not reached");
8001e04c3fSmrg   }
8101e04c3fSmrg
8201e04c3fSmrg   brw_compact_instructions(&c.func, 0, NULL);
8301e04c3fSmrg
8401e04c3fSmrg   *prog_data = c.prog_data;
8501e04c3fSmrg
8601e04c3fSmrg   const unsigned *program = brw_get_program(&c.func, final_assembly_size);
8701e04c3fSmrg
887ec681f3Smrg   if (INTEL_DEBUG(DEBUG_CLIP)) {
8901e04c3fSmrg      fprintf(stderr, "clip:\n");
907ec681f3Smrg      brw_disassemble_with_labels(compiler->devinfo,
917ec681f3Smrg                                  program, 0, *final_assembly_size, stderr);
9201e04c3fSmrg      fprintf(stderr, "\n");
9301e04c3fSmrg   }
9401e04c3fSmrg
9501e04c3fSmrg   return program;
9601e04c3fSmrg}
97