intel/blorp: Explicitly flush all allocated state
[mesa.git] / src / intel / vulkan / genX_blorp_exec.c
1 /*
2 * Copyright © 2016 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25
26 #include "anv_private.h"
27
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
32
33 #include "common/gen_l3_config.h"
34 #include "common/gen_sample_positions.h"
35 #include "blorp/blorp_genX_exec.h"
36
37 static void *
38 blorp_emit_dwords(struct blorp_batch *batch, unsigned n)
39 {
40 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
41 return anv_batch_emit_dwords(&cmd_buffer->batch, n);
42 }
43
44 static uint64_t
45 blorp_emit_reloc(struct blorp_batch *batch,
46 void *location, struct blorp_address address, uint32_t delta)
47 {
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);
53 }
54
55 static void
56 blorp_surface_reloc(struct blorp_batch *batch, uint32_t ss_offset,
57 struct blorp_address address, uint32_t delta)
58 {
59 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
60 anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc,
61 ss_offset, address.buffer, address.offset + delta);
62 }
63
64 static void *
65 blorp_alloc_dynamic_state(struct blorp_batch *batch,
66 enum aub_state_struct_type type,
67 uint32_t size,
68 uint32_t alignment,
69 uint32_t *offset)
70 {
71 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
72
73 struct anv_state state =
74 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, alignment);
75
76 *offset = state.offset;
77 return state.map;
78 }
79
80 static void
81 blorp_alloc_binding_table(struct blorp_batch *batch, unsigned num_entries,
82 unsigned state_size, unsigned state_alignment,
83 uint32_t *bt_offset,
84 uint32_t *surface_offsets, void **surface_maps)
85 {
86 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
87
88 uint32_t state_offset;
89 struct anv_state bt_state =
90 anv_cmd_buffer_alloc_blorp_binding_table(cmd_buffer, num_entries,
91 &state_offset);
92
93 uint32_t *bt_map = bt_state.map;
94 *bt_offset = bt_state.offset;
95
96 for (unsigned i = 0; i < num_entries; i++) {
97 struct anv_state surface_state =
98 anv_cmd_buffer_alloc_surface_state(cmd_buffer);
99 bt_map[i] = surface_state.offset + state_offset;
100 surface_offsets[i] = surface_state.offset;
101 surface_maps[i] = surface_state.map;
102 }
103
104 if (!cmd_buffer->device->info.has_llc)
105 anv_state_clflush(bt_state);
106 }
107
108 static void *
109 blorp_alloc_vertex_buffer(struct blorp_batch *batch, uint32_t size,
110 struct blorp_address *addr)
111 {
112 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
113 struct anv_state vb_state =
114 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, 16);
115
116 *addr = (struct blorp_address) {
117 .buffer = &cmd_buffer->device->dynamic_state_block_pool.bo,
118 .offset = vb_state.offset,
119 };
120
121 return vb_state.map;
122 }
123
124 static void
125 blorp_flush_range(struct blorp_batch *batch, void *start, size_t size)
126 {
127 struct anv_device *device = batch->blorp->driver_ctx;
128 if (!device->info.has_llc)
129 anv_clflush_range(start, size);
130 }
131
132 static void
133 blorp_emit_urb_config(struct blorp_batch *batch, unsigned vs_entry_size)
134 {
135 struct anv_device *device = batch->blorp->driver_ctx;
136 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
137
138 const unsigned entry_size[4] = { vs_entry_size, 1, 1, 1 };
139
140 genX(emit_urb_setup)(device, &cmd_buffer->batch,
141 cmd_buffer->state.current_l3_config,
142 VK_SHADER_STAGE_VERTEX_BIT |
143 VK_SHADER_STAGE_FRAGMENT_BIT,
144 entry_size);
145 }
146
147 void genX(blorp_exec)(struct blorp_batch *batch,
148 const struct blorp_params *params);
149
150 void
151 genX(blorp_exec)(struct blorp_batch *batch,
152 const struct blorp_params *params)
153 {
154 struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
155
156 if (!cmd_buffer->state.current_l3_config) {
157 const struct gen_l3_config *cfg =
158 gen_get_default_l3_config(&cmd_buffer->device->info);
159 genX(cmd_buffer_config_l3)(cmd_buffer, cfg);
160 }
161
162 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
163
164 genX(flush_pipeline_select_3d)(cmd_buffer);
165
166 genX(cmd_buffer_emit_gen7_depth_flush)(cmd_buffer);
167
168 /* BLORP doesn't do anything fancy with depth such as discards, so we want
169 * the PMA fix off. Also, off is always the safe option.
170 */
171 genX(cmd_buffer_enable_pma_fix)(cmd_buffer, false);
172
173 blorp_exec(batch, params);
174
175 cmd_buffer->state.vb_dirty = ~0;
176 cmd_buffer->state.dirty = ~0;
177 cmd_buffer->state.push_constants_dirty = ~0;
178 }