[965] Convert VS unit to use a cache key instead of brw_cache_data.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs_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 #include "macros.h"
38
39 struct brw_vs_unit_key {
40 unsigned int total_grf;
41 unsigned int urb_entry_read_length;
42 unsigned int curb_entry_read_length;
43
44 unsigned int curbe_offset;
45
46 unsigned int nr_urb_entries, urb_size;
47 };
48
49 static void
50 vs_unit_populate_key(struct brw_context *brw, struct brw_vs_unit_key *key)
51 {
52 memset(key, 0, sizeof(*key));
53
54 /* CACHE_NEW_VS_PROG */
55 key->total_grf = brw->vs.prog_data->total_grf;
56 key->urb_entry_read_length = brw->vs.prog_data->urb_read_length;
57 key->curb_entry_read_length = brw->vs.prog_data->curb_read_length;
58
59 /* BRW_NEW_URB_FENCE */
60 key->nr_urb_entries = brw->urb.nr_vs_entries;
61 key->urb_size = brw->urb.vsize;
62
63 /* BRW_NEW_CURBE_OFFSETS, _NEW_TRANSFORM */
64 if (brw->attribs.Transform->ClipPlanesEnabled) {
65 /* Note that we read in the userclip planes as well, hence
66 * clip_start:
67 */
68 key->curbe_offset = brw->curbe.clip_start;
69 }
70 else {
71 key->curbe_offset = brw->curbe.vs_start;
72 }
73 }
74
75 static dri_bo *
76 vs_unit_create_from_key(struct brw_context *brw, struct brw_vs_unit_key *key)
77 {
78 struct brw_vs_unit_state vs;
79
80 memset(&vs, 0, sizeof(vs));
81
82 vs.thread0.kernel_start_pointer = brw->vs.prog_bo->offset >> 6; /* reloc */
83 vs.thread0.grf_reg_count = ALIGN(key->total_grf, 16) / 16 - 1;
84 vs.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754;
85 vs.thread3.urb_entry_read_length = key->urb_entry_read_length;
86 vs.thread3.const_urb_entry_read_length = key->curb_entry_read_length;
87 vs.thread3.dispatch_grf_start_reg = 1;
88 vs.thread3.urb_entry_read_offset = 0;
89 vs.thread3.const_urb_entry_read_offset = key->curbe_offset * 2;
90
91 vs.thread4.nr_urb_entries = key->nr_urb_entries;
92 vs.thread4.urb_entry_allocation_size = key->urb_size - 1;
93 vs.thread4.max_threads = MIN2(MAX2(0, (key->nr_urb_entries - 6) / 2 - 1),
94 15);
95
96 if (INTEL_DEBUG & DEBUG_SINGLE_THREAD)
97 vs.thread4.max_threads = 0;
98
99 /* No samplers for ARB_vp programs:
100 */
101 vs.vs5.sampler_count = 0;
102
103 if (INTEL_DEBUG & DEBUG_STATS)
104 vs.thread4.stats_enable = 1;
105
106 /* Vertex program always enabled:
107 */
108 vs.vs6.vs_enable = 1;
109
110 brw->vs.thread0_delta = vs.thread0.grf_reg_count << 1;
111 return brw_upload_cache(&brw->cache, BRW_VS_UNIT,
112 key, sizeof(*key),
113 &brw->vs.prog_bo, 1,
114 &vs, sizeof(vs),
115 NULL, NULL);
116 }
117
118 static void upload_vs_unit( struct brw_context *brw )
119 {
120 struct brw_vs_unit_key key;
121
122 vs_unit_populate_key(brw, &key);
123
124 dri_bo_unreference(brw->vs.state_bo);
125 brw->vs.state_bo = brw_search_cache(&brw->cache, BRW_VS_UNIT,
126 &key, sizeof(key),
127 &brw->vs.prog_bo, 1,
128 NULL);
129 if (brw->vs.state_bo == NULL) {
130 brw->vs.state_bo = vs_unit_create_from_key(brw, &key);
131 }
132 }
133
134 static void emit_reloc_vs_unit(struct brw_context *brw)
135 {
136 /* Emit VS program relocation */
137 dri_emit_reloc(brw->vs.state_bo,
138 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
139 brw->vs.thread0_delta,
140 offsetof(struct brw_vs_unit_state, thread0),
141 brw->vs.prog_bo);
142 }
143
144 const struct brw_tracked_state brw_vs_unit = {
145 .dirty = {
146 .mesa = _NEW_TRANSFORM,
147 .brw = (BRW_NEW_CURBE_OFFSETS |
148 BRW_NEW_URB_FENCE),
149 .cache = CACHE_NEW_VS_PROG
150 },
151 .update = upload_vs_unit,
152 .emit_reloc = emit_reloc_vs_unit,
153 };