intel: Annotate debug printout checks with unlikely().
[mesa.git] / src / mesa / drivers / dri / i965 / brw_gs_state.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33
34 #include "brw_context.h"
35 #include "brw_state.h"
36 #include "brw_defines.h"
37
38 struct brw_gs_unit_key {
39 unsigned int total_grf;
40 unsigned int urb_entry_read_length;
41
42 unsigned int curbe_offset;
43
44 unsigned int nr_urb_entries, urb_size;
45 GLboolean prog_active;
46 };
47
48 static void
49 gs_unit_populate_key(struct brw_context *brw, struct brw_gs_unit_key *key)
50 {
51 memset(key, 0, sizeof(*key));
52
53 /* CACHE_NEW_GS_PROG */
54 key->prog_active = brw->gs.prog_active;
55 if (key->prog_active) {
56 key->total_grf = brw->gs.prog_data->total_grf;
57 key->urb_entry_read_length = brw->gs.prog_data->urb_read_length;
58 } else {
59 key->total_grf = 1;
60 key->urb_entry_read_length = 1;
61 }
62
63 /* BRW_NEW_CURBE_OFFSETS */
64 key->curbe_offset = brw->curbe.clip_start;
65
66 /* BRW_NEW_URB_FENCE */
67 key->nr_urb_entries = brw->urb.nr_gs_entries;
68 key->urb_size = brw->urb.vsize;
69 }
70
71 static drm_intel_bo *
72 gs_unit_create_from_key(struct brw_context *brw, struct brw_gs_unit_key *key)
73 {
74 struct intel_context *intel = &brw->intel;
75 struct brw_gs_unit_state gs;
76 drm_intel_bo *bo;
77
78 memset(&gs, 0, sizeof(gs));
79
80 gs.thread0.grf_reg_count = ALIGN(key->total_grf, 16) / 16 - 1;
81 if (key->prog_active) /* reloc */
82 gs.thread0.kernel_start_pointer = brw->gs.prog_bo->offset >> 6;
83
84 gs.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754;
85 gs.thread1.single_program_flow = 1;
86
87 gs.thread3.dispatch_grf_start_reg = 1;
88 gs.thread3.const_urb_entry_read_offset = 0;
89 gs.thread3.const_urb_entry_read_length = 0;
90 gs.thread3.urb_entry_read_offset = 0;
91 gs.thread3.urb_entry_read_length = key->urb_entry_read_length;
92
93 gs.thread4.nr_urb_entries = key->nr_urb_entries;
94 gs.thread4.urb_entry_allocation_size = key->urb_size - 1;
95
96 if (key->nr_urb_entries >= 8)
97 gs.thread4.max_threads = 1;
98 else
99 gs.thread4.max_threads = 0;
100
101 if (intel->gen == 5)
102 gs.thread4.rendering_enable = 1;
103
104 if (unlikely(INTEL_DEBUG & DEBUG_STATS))
105 gs.thread4.stats_enable = 1;
106
107 bo = brw_upload_cache(&brw->cache, BRW_GS_UNIT,
108 key, sizeof(*key),
109 &brw->gs.prog_bo, 1,
110 &gs, sizeof(gs));
111
112 if (key->prog_active) {
113 /* Emit GS program relocation */
114 drm_intel_bo_emit_reloc(bo, offsetof(struct brw_gs_unit_state, thread0),
115 brw->gs.prog_bo, gs.thread0.grf_reg_count << 1,
116 I915_GEM_DOMAIN_INSTRUCTION, 0);
117 }
118
119 return bo;
120 }
121
122 static void prepare_gs_unit(struct brw_context *brw)
123 {
124 struct brw_gs_unit_key key;
125
126 gs_unit_populate_key(brw, &key);
127
128 drm_intel_bo_unreference(brw->gs.state_bo);
129 brw->gs.state_bo = brw_search_cache(&brw->cache, BRW_GS_UNIT,
130 &key, sizeof(key),
131 &brw->gs.prog_bo, 1,
132 NULL);
133 if (brw->gs.state_bo == NULL) {
134 brw->gs.state_bo = gs_unit_create_from_key(brw, &key);
135 }
136 }
137
138 const struct brw_tracked_state brw_gs_unit = {
139 .dirty = {
140 .mesa = 0,
141 .brw = (BRW_NEW_CURBE_OFFSETS |
142 BRW_NEW_URB_FENCE),
143 .cache = CACHE_NEW_GS_PROG
144 },
145 .prepare = prepare_gs_unit,
146 };