brw_clip_state.c revision 8e444fb9e2685e3eac42beb848b08e91dc20c88a
1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson/* 2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson Copyright (C) Intel Corp. 2006. All Rights Reserved. 3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to 4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson develop this 3D driver. 5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson Permission is hereby granted, free of charge, to any person obtaining 7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson a copy of this software and associated documentation files (the 8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson "Software"), to deal in the Software without restriction, including 9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson without limitation the rights to use, copy, modify, merge, publish, 10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson distribute, sublicense, and/or sell copies of the Software, and to 11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson permit persons to whom the Software is furnished to do so, subject to 12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson the following conditions: 13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson The above copyright notice and this permission notice (including the 15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson next paragraph) shall be included in all copies or substantial 16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson portions of the Software. 17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson **********************************************************************/ 27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson /* 28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * Authors: 29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * Keith Whitwell <keith@tungstengraphics.com> 30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson */ 31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include "brw_context.h" 33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include "brw_state.h" 34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include "brw_defines.h" 35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include "macros.h" 36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonstruct brw_clip_unit_key { 38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int total_grf; 39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int urb_entry_read_length; 40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int curb_entry_read_length; 41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int clip_mode; 42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int curbe_offset; 44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson unsigned int nr_urb_entries, urb_size; 46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}; 47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonstatic void 49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonclip_unit_populate_key(struct brw_context *brw, struct brw_clip_unit_key *key) 50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson{ 51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson memset(key, 0, sizeof(*key)); 52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson /* CACHE_NEW_CLIP_PROG */ 54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->total_grf = brw->clip.prog_data->total_grf; 55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->urb_entry_read_length = brw->clip.prog_data->urb_read_length; 56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->curb_entry_read_length = brw->clip.prog_data->curb_read_length; 57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->clip_mode = brw->clip.prog_data->clip_mode; 58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 59f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson /* BRW_NEW_CURBE_OFFSETS */ 60f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->curbe_offset = brw->curbe.clip_start; 61f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson /* BRW_NEW_URB_FENCE */ 63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->nr_urb_entries = brw->urb.nr_clip_entries; 64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson key->urb_size = brw->urb.vsize; 65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} 66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonstatic dri_bo * 68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonclip_unit_create_from_key(struct brw_context *brw, 69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson struct brw_clip_unit_key *key) 70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson{ 71f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson struct brw_clip_unit_state clip; 72f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson dri_bo *bo; 73f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 74f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson memset(&clip, 0, sizeof(clip)); 75f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 76f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson clip.thread0.grf_reg_count = ALIGN(key->total_grf, 16) / 16 - 1; 77 /* reloc */ 78 clip.thread0.kernel_start_pointer = brw->clip.prog_bo->offset >> 6; 79 80 clip.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; 81 clip.thread1.single_program_flow = 1; 82 83 clip.thread3.urb_entry_read_length = key->urb_entry_read_length; 84 clip.thread3.const_urb_entry_read_length = key->curb_entry_read_length; 85 clip.thread3.const_urb_entry_read_offset = key->curbe_offset * 2; 86 clip.thread3.dispatch_grf_start_reg = 1; 87 clip.thread3.urb_entry_read_offset = 0; 88 89 clip.thread4.nr_urb_entries = key->nr_urb_entries; 90 clip.thread4.urb_entry_allocation_size = key->urb_size - 1; 91 clip.thread4.max_threads = 1; /* 2 threads */ 92 93 if (INTEL_DEBUG & DEBUG_STATS) 94 clip.thread4.stats_enable = 1; 95 96 clip.clip5.userclip_enable_flags = 0x7f; 97 clip.clip5.userclip_must_clip = 1; 98 clip.clip5.guard_band_enable = 0; 99 clip.clip5.viewport_z_clip_enable = 1; 100 clip.clip5.viewport_xy_clip_enable = 1; 101 clip.clip5.vertex_position_space = BRW_CLIP_NDCSPACE; 102 clip.clip5.api_mode = BRW_CLIP_API_OGL; 103 clip.clip5.clip_mode = key->clip_mode; 104 105 if (BRW_IS_IGD(brw)) 106 clip.clip5.negative_w_clip_test = 1; 107 108 clip.clip6.clipper_viewport_state_ptr = 0; 109 clip.viewport_xmin = -1; 110 clip.viewport_xmax = 1; 111 clip.viewport_ymin = -1; 112 clip.viewport_ymax = 1; 113 114 bo = brw_upload_cache(&brw->cache, BRW_CLIP_UNIT, 115 key, sizeof(*key), 116 &brw->clip.prog_bo, 1, 117 &clip, sizeof(clip), 118 NULL, NULL); 119 120 /* Emit clip program relocation */ 121 assert(brw->clip.prog_bo); 122 dri_emit_reloc(bo, 123 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 124 clip.thread0.grf_reg_count << 1, 125 offsetof(struct brw_clip_unit_state, thread0), 126 brw->clip.prog_bo); 127 128 return bo; 129} 130 131static void upload_clip_unit( struct brw_context *brw ) 132{ 133 struct brw_clip_unit_key key; 134 135 clip_unit_populate_key(brw, &key); 136 137 dri_bo_unreference(brw->clip.state_bo); 138 brw->clip.state_bo = brw_search_cache(&brw->cache, BRW_CLIP_UNIT, 139 &key, sizeof(key), 140 &brw->clip.prog_bo, 1, 141 NULL); 142 if (brw->clip.state_bo == NULL) { 143 brw->clip.state_bo = clip_unit_create_from_key(brw, &key); 144 } 145} 146 147const struct brw_tracked_state brw_clip_unit = { 148 .dirty = { 149 .mesa = 0, 150 .brw = (BRW_NEW_CURBE_OFFSETS | 151 BRW_NEW_URB_FENCE), 152 .cache = CACHE_NEW_CLIP_PROG 153 }, 154 .update = upload_clip_unit, 155}; 156