2 * Copyright © 2018 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 #ifndef GENX_BOILERPLATE_H
24 #define GENX_BOILERPLATE_H
28 #include "genxml/gen_macros.h"
30 #include "brw_context.h"
31 #include "intel_batchbuffer.h"
34 emit_dwords(struct brw_context
*brw
, unsigned n
)
36 intel_batchbuffer_begin(brw
, n
);
37 uint32_t *map
= brw
->batch
.map_next
;
38 brw
->batch
.map_next
+= n
;
39 intel_batchbuffer_advance(brw
);
49 #define __gen_address_type struct brw_address
50 #define __gen_user_data struct brw_context
53 __gen_combine_address(struct brw_context
*brw
, void *location
,
54 struct brw_address address
, uint32_t delta
)
56 struct intel_batchbuffer
*batch
= &brw
->batch
;
59 if (address
.bo
== NULL
) {
60 return address
.offset
+ delta
;
62 if (GEN_GEN
< 6 && brw_ptr_in_state_buffer(batch
, location
)) {
63 offset
= (char *) location
- (char *) brw
->batch
.state
.map
;
64 return brw_state_reloc(batch
, offset
, address
.bo
,
65 address
.offset
+ delta
,
69 assert(!brw_ptr_in_state_buffer(batch
, location
));
71 offset
= (char *) location
- (char *) brw
->batch
.batch
.map
;
72 return brw_batch_reloc(batch
, offset
, address
.bo
,
73 address
.offset
+ delta
,
78 UNUSED
static struct brw_address
79 rw_bo(struct brw_bo
*bo
, uint32_t offset
)
81 return (struct brw_address
) {
84 .reloc_flags
= RELOC_WRITE
,
88 UNUSED
static struct brw_address
89 ro_bo(struct brw_bo
*bo
, uint32_t offset
)
91 return (struct brw_address
) {
97 UNUSED
static struct brw_address
98 rw_32_bo(struct brw_bo
*bo
, uint32_t offset
)
100 return (struct brw_address
) {
103 .reloc_flags
= RELOC_WRITE
| RELOC_32BIT
,
107 UNUSED
static struct brw_address
108 ro_32_bo(struct brw_bo
*bo
, uint32_t offset
)
110 return (struct brw_address
) {
113 .reloc_flags
= RELOC_32BIT
,
117 UNUSED
static struct brw_address
118 ggtt_bo(struct brw_bo
*bo
, uint32_t offset
)
120 return (struct brw_address
) {
123 .reloc_flags
= RELOC_WRITE
| RELOC_NEEDS_GGTT
,
127 #include "genxml/genX_pack.h"
129 #define _brw_cmd_length(cmd) cmd ## _length
130 #define _brw_cmd_length_bias(cmd) cmd ## _length_bias
131 #define _brw_cmd_header(cmd) cmd ## _header
132 #define _brw_cmd_pack(cmd) cmd ## _pack
134 #define brw_batch_emit(brw, cmd, name) \
135 for (struct cmd name = { _brw_cmd_header(cmd) }, \
136 *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
137 __builtin_expect(_dst != NULL, 1); \
138 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
141 #define brw_batch_emitn(brw, cmd, n, ...) ({ \
142 uint32_t *_dw = emit_dwords(brw, n); \
143 struct cmd template = { \
144 _brw_cmd_header(cmd), \
145 .DWordLength = n - _brw_cmd_length_bias(cmd), \
148 _brw_cmd_pack(cmd)(brw, _dw, &template); \
149 _dw + 1; /* Array starts at dw[1] */ \
152 #define brw_state_emit(brw, cmd, align, offset, name) \
153 for (struct cmd name = {}, \
154 *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4, \
156 __builtin_expect(_dst != NULL, 1); \
157 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \