1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/*
* Copyright © 2012 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
/**************************************************************************
*
* Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "intel/intel_batchbuffer.h"
#include "intel/intel_driver.h"
#include "cl_alloc.h"
#include "cl_utils.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
LOCAL void
intel_batchbuffer_reset(intel_batchbuffer_t *batch, size_t sz)
{
if (batch->buffer != NULL) {
dri_bo_unreference(batch->buffer);
batch->buffer = NULL;
batch->last_bo = NULL;
}
batch->buffer = dri_bo_alloc(batch->intel->bufmgr,
"batch buffer",
sz,
64);
assert(batch->buffer);
dri_bo_map(batch->buffer, 1);
batch->map = (uint8_t*) batch->buffer->virtual;
batch->size = sz;
batch->ptr = batch->map;
batch->atomic = 0;
batch->last_bo = batch->buffer;
batch->enable_slm = 0;
}
LOCAL void
intel_batchbuffer_init(intel_batchbuffer_t *batch, intel_driver_t *intel)
{
assert(intel);
batch->intel = intel;
}
LOCAL void
intel_batchbuffer_terminate(intel_batchbuffer_t *batch)
{
assert(batch->buffer);
if (batch->map) {
dri_bo_unmap(batch->buffer);
batch->map = NULL;
}
dri_bo_unreference(batch->buffer);
batch->buffer = NULL;
}
LOCAL void
intel_batchbuffer_flush(intel_batchbuffer_t *batch)
{
uint32_t used = batch->ptr - batch->map;
int is_locked = batch->intel->locked;
if (used == 0)
return;
if ((used & 4) == 0) {
*(uint32_t*) batch->ptr = 0;
batch->ptr += 4;
}
*(uint32_t*)batch->ptr = MI_BATCH_BUFFER_END;
batch->ptr += 4;
dri_bo_unmap(batch->buffer);
used = batch->ptr - batch->map;
if (!is_locked)
intel_driver_lock_hardware(batch->intel);
int flag = I915_EXEC_RENDER;
if(batch->enable_slm) {
/* use the hard code here temp, must change to
* I915_EXEC_ENABLE_SLM when it drm accept the patch */
flag |= (1<<13);
}
drm_intel_gem_bo_context_exec(batch->buffer, batch->intel->ctx, used, flag);
if (!is_locked)
intel_driver_unlock_hardware(batch->intel);
// Release the buffer
intel_batchbuffer_terminate(batch);
}
LOCAL void
intel_batchbuffer_emit_reloc(intel_batchbuffer_t *batch,
dri_bo *bo,
uint32_t read_domains,
uint32_t write_domains,
uint32_t delta)
{
assert(batch->ptr - batch->map < batch->size);
dri_bo_emit_reloc(batch->buffer,
read_domains,
write_domains,
delta,
batch->ptr - batch->map,
bo);
intel_batchbuffer_emit_dword(batch, bo->offset + delta);
}
LOCAL void
intel_batchbuffer_emit_mi_flush(intel_batchbuffer_t *batch)
{
intel_batchbuffer_require_space(batch, 4);
intel_batchbuffer_emit_dword(batch, MI_FLUSH | STATE_INSTRUCTION_CACHE_INVALIDATE);
}
LOCAL intel_batchbuffer_t*
intel_batchbuffer_new(intel_driver_t *intel)
{
intel_batchbuffer_t *batch = NULL;
assert(intel);
TRY_ALLOC_NO_ERR (batch, CALLOC(intel_batchbuffer_t));
intel_batchbuffer_init(batch, intel);
exit:
return batch;
error:
intel_batchbuffer_delete(batch);
batch = NULL;
goto exit;
}
LOCAL void
intel_batchbuffer_delete(intel_batchbuffer_t *batch)
{
if (batch == NULL)
return;
if(batch->buffer)
intel_batchbuffer_terminate(batch);
cl_free(batch);
}
|