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
|
/*
* Copyright © 2018 Intel Corporation
*
* 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, sublicense,
* 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 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 NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#ifndef GENX_BOILERPLATE_H
#define GENX_BOILERPLATE_H
#include <assert.h>
#include "genxml/gen_macros.h"
#include "brw_context.h"
#include "intel_batchbuffer.h"
UNUSED static void *
emit_dwords(struct brw_context *brw, unsigned n)
{
intel_batchbuffer_begin(brw, n);
uint32_t *map = brw->batch.map_next;
brw->batch.map_next += n;
intel_batchbuffer_advance(brw);
return map;
}
struct brw_address {
struct brw_bo *bo;
unsigned reloc_flags;
uint32_t offset;
};
#define __gen_address_type struct brw_address
#define __gen_user_data struct brw_context
static uint64_t
__gen_combine_address(struct brw_context *brw, void *location,
struct brw_address address, uint32_t delta)
{
struct intel_batchbuffer *batch = &brw->batch;
uint32_t offset;
if (address.bo == NULL) {
return address.offset + delta;
} else {
if (GEN_GEN < 6 && brw_ptr_in_state_buffer(batch, location)) {
offset = (char *) location - (char *) brw->batch.state.map;
return brw_state_reloc(batch, offset, address.bo,
address.offset + delta,
address.reloc_flags);
}
assert(!brw_ptr_in_state_buffer(batch, location));
offset = (char *) location - (char *) brw->batch.batch.map;
return brw_batch_reloc(batch, offset, address.bo,
address.offset + delta,
address.reloc_flags);
}
}
UNUSED static struct brw_address
rw_bo(struct brw_bo *bo, uint32_t offset)
{
return (struct brw_address) {
.bo = bo,
.offset = offset,
.reloc_flags = RELOC_WRITE,
};
}
UNUSED static struct brw_address
ro_bo(struct brw_bo *bo, uint32_t offset)
{
return (struct brw_address) {
.bo = bo,
.offset = offset,
};
}
UNUSED static struct brw_address
rw_32_bo(struct brw_bo *bo, uint32_t offset)
{
return (struct brw_address) {
.bo = bo,
.offset = offset,
.reloc_flags = RELOC_WRITE | RELOC_32BIT,
};
}
UNUSED static struct brw_address
ro_32_bo(struct brw_bo *bo, uint32_t offset)
{
return (struct brw_address) {
.bo = bo,
.offset = offset,
.reloc_flags = RELOC_32BIT,
};
}
UNUSED static struct brw_address
ggtt_bo(struct brw_bo *bo, uint32_t offset)
{
return (struct brw_address) {
.bo = bo,
.offset = offset,
.reloc_flags = RELOC_WRITE | RELOC_NEEDS_GGTT,
};
}
#include "genxml/genX_pack.h"
#define _brw_cmd_length(cmd) cmd ## _length
#define _brw_cmd_length_bias(cmd) cmd ## _length_bias
#define _brw_cmd_header(cmd) cmd ## _header
#define _brw_cmd_pack(cmd) cmd ## _pack
#define brw_batch_emit(brw, cmd, name) \
for (struct cmd name = { _brw_cmd_header(cmd) }, \
*_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
__builtin_expect(_dst != NULL, 1); \
_brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
_dst = NULL)
#define brw_batch_emitn(brw, cmd, n, ...) ({ \
uint32_t *_dw = emit_dwords(brw, n); \
struct cmd template = { \
_brw_cmd_header(cmd), \
.DWordLength = n - _brw_cmd_length_bias(cmd), \
__VA_ARGS__ \
}; \
_brw_cmd_pack(cmd)(brw, _dw, &template); \
_dw + 1; /* Array starts at dw[1] */ \
})
#define brw_state_emit(brw, cmd, align, offset, name) \
for (struct cmd name = {}, \
*_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4, \
align, offset); \
__builtin_expect(_dst != NULL, 1); \
_brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
_dst = NULL)
#endif
|