Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_pool.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 #include "brw_state.h"
34 #include "imports.h"
35
36 #include "intel_ioctl.h"
37 #include "bufmgr.h"
38
39 GLboolean brw_pool_alloc( struct brw_mem_pool *pool,
40 GLuint size,
41 GLuint align,
42 GLuint *offset_return)
43 {
44 GLuint align_mask = (1<<align)-1;
45 GLuint fixup = ((pool->offset + align_mask) & ~align_mask) - pool->offset;
46
47 size = (size + 3) & ~3;
48
49 if (pool->offset + fixup + size >= pool->size) {
50 assert(0);
51 exit(0);
52 }
53
54 pool->offset += fixup;
55 *offset_return = pool->offset;
56 pool->offset += size;
57
58 return GL_TRUE;
59 }
60
61 static
62 void brw_invalidate_pool( struct intel_context *intel,
63 struct brw_mem_pool *pool )
64 {
65 if (INTEL_DEBUG & DEBUG_STATE)
66 _mesa_printf("\n\n\n %s \n\n\n", __FUNCTION__);
67
68 bmBufferData(intel,
69 pool->buffer,
70 pool->size,
71 NULL,
72 0);
73
74 pool->offset = 0;
75
76 brw_clear_all_caches(pool->brw);
77 }
78
79 static void brw_invalidate_pool_cb( struct intel_context *intel, void *ptr )
80 {
81 struct brw_mem_pool *pool = (struct brw_mem_pool *) ptr;
82
83 pool->offset = 0;
84 brw_clear_all_caches(pool->brw);
85 }
86
87
88
89 static void brw_init_pool( struct brw_context *brw,
90 GLuint pool_id,
91 GLuint size )
92 {
93 struct brw_mem_pool *pool = &brw->pool[pool_id];
94
95 pool->size = size;
96 pool->brw = brw;
97
98 bmGenBuffers(&brw->intel, "pool", 1, &pool->buffer);
99
100 /* Also want to say not to wait on fences when data is presented
101 */
102 bmBufferSetInvalidateCB(&brw->intel, pool->buffer,
103 brw_invalidate_pool_cb,
104 pool,
105 GL_TRUE);
106
107 bmBufferData(&brw->intel,
108 pool->buffer,
109 pool->size,
110 NULL,
111 0);
112
113 }
114
115 static void brw_destroy_pool( struct brw_context *brw,
116 GLuint pool_id )
117 {
118 struct brw_mem_pool *pool = &brw->pool[pool_id];
119
120 bmDeleteBuffers(&brw->intel, 1, &pool->buffer);
121 }
122
123
124 void brw_pool_check_wrap( struct brw_context *brw,
125 struct brw_mem_pool *pool )
126 {
127 if (pool->offset > (pool->size * 3) / 4) {
128 if (brw->intel.aub_file)
129 brw->intel.aub_wrap = 1;
130 else
131 brw->state.dirty.brw |= BRW_NEW_CONTEXT;
132 }
133
134 }
135
136 void brw_init_pools( struct brw_context *brw )
137 {
138 brw_init_pool(brw, BRW_GS_POOL, 0x80000);
139 brw_init_pool(brw, BRW_SS_POOL, 0x80000);
140 }
141
142 void brw_destroy_pools( struct brw_context *brw )
143 {
144 brw_destroy_pool(brw, BRW_GS_POOL);
145 brw_destroy_pool(brw, BRW_SS_POOL);
146 }
147
148
149 void brw_invalidate_pools( struct brw_context *brw )
150 {
151 brw_invalidate_pool(&brw->intel, &brw->pool[BRW_GS_POOL]);
152 brw_invalidate_pool(&brw->intel, &brw->pool[BRW_SS_POOL]);
153 }