2 * Copyright © 2016 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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "anv_private.h"
28 /* These are defined in anv_private.h and blorp_genX_exec.h */
29 #undef __gen_address_type
30 #undef __gen_user_data
31 #undef __gen_combine_address
33 #include "common/gen_l3_config.h"
34 #include "common/gen_sample_positions.h"
35 #include "blorp/blorp_genX_exec.h"
38 blorp_emit_dwords(struct blorp_batch
*batch
, unsigned n
)
40 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
41 return anv_batch_emit_dwords(&cmd_buffer
->batch
, n
);
45 blorp_emit_reloc(struct blorp_batch
*batch
,
46 void *location
, struct blorp_address address
, uint32_t delta
)
48 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
49 assert(cmd_buffer
->batch
.start
<= location
&&
50 location
< cmd_buffer
->batch
.end
);
51 return anv_batch_emit_reloc(&cmd_buffer
->batch
, location
,
52 address
.buffer
, address
.offset
+ delta
);
56 blorp_surface_reloc(struct blorp_batch
*batch
, uint32_t ss_offset
,
57 struct blorp_address address
, uint32_t delta
)
59 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
61 anv_reloc_list_add(&cmd_buffer
->surface_relocs
, &cmd_buffer
->pool
->alloc
,
62 ss_offset
, address
.buffer
, address
.offset
+ delta
);
63 if (result
!= VK_SUCCESS
)
64 anv_batch_set_error(&cmd_buffer
->batch
, result
);
68 blorp_alloc_dynamic_state(struct blorp_batch
*batch
,
73 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
75 struct anv_state state
=
76 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, size
, alignment
);
78 *offset
= state
.offset
;
83 blorp_alloc_binding_table(struct blorp_batch
*batch
, unsigned num_entries
,
84 unsigned state_size
, unsigned state_alignment
,
86 uint32_t *surface_offsets
, void **surface_maps
)
88 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
90 uint32_t state_offset
;
91 struct anv_state bt_state
;
94 anv_cmd_buffer_alloc_blorp_binding_table(cmd_buffer
, num_entries
,
95 &state_offset
, &bt_state
);
96 if (result
!= VK_SUCCESS
)
99 uint32_t *bt_map
= bt_state
.map
;
100 *bt_offset
= bt_state
.offset
;
102 for (unsigned i
= 0; i
< num_entries
; i
++) {
103 struct anv_state surface_state
=
104 anv_cmd_buffer_alloc_surface_state(cmd_buffer
);
105 bt_map
[i
] = surface_state
.offset
+ state_offset
;
106 surface_offsets
[i
] = surface_state
.offset
;
107 surface_maps
[i
] = surface_state
.map
;
110 anv_state_flush(cmd_buffer
->device
, bt_state
);
114 blorp_alloc_vertex_buffer(struct blorp_batch
*batch
, uint32_t size
,
115 struct blorp_address
*addr
)
117 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
119 /* From the Skylake PRM, 3DSTATE_VERTEX_BUFFERS:
121 * "The VF cache needs to be invalidated before binding and then using
122 * Vertex Buffers that overlap with any previously bound Vertex Buffer
123 * (at a 64B granularity) since the last invalidation. A VF cache
124 * invalidate is performed by setting the "VF Cache Invalidation Enable"
125 * bit in PIPE_CONTROL."
127 * This restriction first appears in the Skylake PRM but the internal docs
128 * also list it as being an issue on Broadwell. In order to avoid this
129 * problem, we align all vertex buffer allocations to 64 bytes.
131 struct anv_state vb_state
=
132 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, size
, 64);
134 *addr
= (struct blorp_address
) {
135 .buffer
= &cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
,
136 .offset
= vb_state
.offset
,
143 blorp_flush_range(struct blorp_batch
*batch
, void *start
, size_t size
)
145 struct anv_device
*device
= batch
->blorp
->driver_ctx
;
146 if (!device
->info
.has_llc
)
147 anv_flush_range(start
, size
);
151 blorp_emit_urb_config(struct blorp_batch
*batch
,
152 unsigned vs_entry_size
, unsigned sf_entry_size
)
154 struct anv_device
*device
= batch
->blorp
->driver_ctx
;
155 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
157 assert(sf_entry_size
== 0);
159 const unsigned entry_size
[4] = { vs_entry_size
, 1, 1, 1 };
161 genX(emit_urb_setup
)(device
, &cmd_buffer
->batch
,
162 cmd_buffer
->state
.current_l3_config
,
163 VK_SHADER_STAGE_VERTEX_BIT
|
164 VK_SHADER_STAGE_FRAGMENT_BIT
,
169 genX(blorp_exec
)(struct blorp_batch
*batch
,
170 const struct blorp_params
*params
)
172 struct anv_cmd_buffer
*cmd_buffer
= batch
->driver_batch
;
174 if (!cmd_buffer
->state
.current_l3_config
) {
175 const struct gen_l3_config
*cfg
=
176 gen_get_default_l3_config(&cmd_buffer
->device
->info
);
177 genX(cmd_buffer_config_l3
)(cmd_buffer
, cfg
);
180 genX(cmd_buffer_apply_pipe_flushes
)(cmd_buffer
);
182 genX(flush_pipeline_select_3d
)(cmd_buffer
);
184 genX(cmd_buffer_emit_gen7_depth_flush
)(cmd_buffer
);
186 /* BLORP doesn't do anything fancy with depth such as discards, so we want
187 * the PMA fix off. Also, off is always the safe option.
189 genX(cmd_buffer_enable_pma_fix
)(cmd_buffer
, false);
191 /* Disable VF statistics */
192 blorp_emit(batch
, GENX(3DSTATE_VF_STATISTICS
), vf
) {
193 vf
.StatisticsEnable
= false;
196 blorp_exec(batch
, params
);
198 cmd_buffer
->state
.vb_dirty
= ~0;
199 cmd_buffer
->state
.dirty
= ~0;
200 cmd_buffer
->state
.push_constants_dirty
= ~0;