2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "brw_context.h"
35 #include "brw_state.h"
36 #include "brw_defines.h"
37 #include "main/macros.h"
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
;
44 unsigned int curbe_offset
;
46 unsigned int nr_urb_entries
, urb_size
;
50 vs_unit_populate_key(struct brw_context
*brw
, struct brw_vs_unit_key
*key
)
52 GLcontext
*ctx
= &brw
->intel
.ctx
;
54 memset(key
, 0, sizeof(*key
));
56 /* CACHE_NEW_VS_PROG */
57 key
->total_grf
= brw
->vs
.prog_data
->total_grf
;
58 key
->urb_entry_read_length
= brw
->vs
.prog_data
->urb_read_length
;
59 key
->curb_entry_read_length
= brw
->vs
.prog_data
->curb_read_length
;
61 /* BRW_NEW_URB_FENCE */
62 key
->nr_urb_entries
= brw
->urb
.nr_vs_entries
;
63 key
->urb_size
= brw
->urb
.vsize
;
65 /* BRW_NEW_CURBE_OFFSETS, _NEW_TRANSFORM */
66 if (ctx
->Transform
.ClipPlanesEnabled
) {
67 /* Note that we read in the userclip planes as well, hence
70 key
->curbe_offset
= brw
->curbe
.clip_start
;
73 key
->curbe_offset
= brw
->curbe
.vs_start
;
78 vs_unit_create_from_key(struct brw_context
*brw
, struct brw_vs_unit_key
*key
)
80 struct brw_vs_unit_state vs
;
82 int chipset_max_threads
;
84 memset(&vs
, 0, sizeof(vs
));
86 vs
.thread0
.kernel_start_pointer
= brw
->vs
.prog_bo
->offset
>> 6; /* reloc */
87 vs
.thread0
.grf_reg_count
= ALIGN(key
->total_grf
, 16) / 16 - 1;
88 vs
.thread1
.floating_point_mode
= BRW_FLOATING_POINT_NON_IEEE_754
;
89 /* Choosing multiple program flow means that we may get 2-vertex threads,
90 * which will have the channel mask for dwords 4-7 enabled in the thread,
91 * and those dwords will be written to the second URB handle when we
92 * brw_urb_WRITE() results.
94 vs
.thread1
.single_program_flow
= 0;
95 vs
.thread3
.urb_entry_read_length
= key
->urb_entry_read_length
;
96 vs
.thread3
.const_urb_entry_read_length
= key
->curb_entry_read_length
;
97 vs
.thread3
.dispatch_grf_start_reg
= 1;
98 vs
.thread3
.urb_entry_read_offset
= 0;
99 vs
.thread3
.const_urb_entry_read_offset
= key
->curbe_offset
* 2;
101 vs
.thread4
.nr_urb_entries
= key
->nr_urb_entries
;
102 vs
.thread4
.urb_entry_allocation_size
= key
->urb_size
- 1;
105 chipset_max_threads
= 32;
107 chipset_max_threads
= 16;
108 vs
.thread4
.max_threads
= CLAMP(key
->nr_urb_entries
/ 2,
109 1, chipset_max_threads
) - 1;
111 if (INTEL_DEBUG
& DEBUG_SINGLE_THREAD
)
112 vs
.thread4
.max_threads
= 0;
114 /* No samplers for ARB_vp programs:
116 vs
.vs5
.sampler_count
= 0;
118 if (INTEL_DEBUG
& DEBUG_STATS
)
119 vs
.thread4
.stats_enable
= 1;
121 /* Vertex program always enabled:
123 vs
.vs6
.vs_enable
= 1;
125 bo
= brw_upload_cache(&brw
->cache
, BRW_VS_UNIT
,
131 /* Emit VS program relocation */
132 dri_bo_emit_reloc(bo
,
133 I915_GEM_DOMAIN_INSTRUCTION
, 0,
134 vs
.thread0
.grf_reg_count
<< 1,
135 offsetof(struct brw_vs_unit_state
, thread0
),
141 static void prepare_vs_unit(struct brw_context
*brw
)
143 struct brw_vs_unit_key key
;
145 vs_unit_populate_key(brw
, &key
);
147 dri_bo_unreference(brw
->vs
.state_bo
);
148 brw
->vs
.state_bo
= brw_search_cache(&brw
->cache
, BRW_VS_UNIT
,
152 if (brw
->vs
.state_bo
== NULL
) {
153 brw
->vs
.state_bo
= vs_unit_create_from_key(brw
, &key
);
157 const struct brw_tracked_state brw_vs_unit
= {
159 .mesa
= _NEW_TRANSFORM
,
160 .brw
= (BRW_NEW_CURBE_OFFSETS
|
162 .cache
= CACHE_NEW_VS_PROG
164 .prepare
= prepare_vs_unit
,