1 #include "media_fill.h"
2 #include "gen8_media.h"
7 #define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1))
9 static const uint32_t media_kernel[][4] = {
10 { 0x00400001, 0x20202288, 0x00000020, 0x00000000 },
11 { 0x00600001, 0x20800208, 0x008d0000, 0x00000000 },
12 { 0x00200001, 0x20800208, 0x00450040, 0x00000000 },
13 { 0x00000001, 0x20880608, 0x00000000, 0x000f000f },
14 { 0x00800001, 0x20a00208, 0x00000020, 0x00000000 },
15 { 0x00800001, 0x20e00208, 0x00000020, 0x00000000 },
16 { 0x00800001, 0x21200208, 0x00000020, 0x00000000 },
17 { 0x00800001, 0x21600208, 0x00000020, 0x00000000 },
18 { 0x0c800031, 0x24000a40, 0x0e000080, 0x120a8000 },
19 { 0x00600001, 0x2e000208, 0x008d0000, 0x00000000 },
20 { 0x07800031, 0x20000a40, 0x0e000e00, 0x82000010 },
24 batch_used(struct intel_batchbuffer *batch)
26 return batch->ptr - batch->buffer;
30 batch_align(struct intel_batchbuffer *batch, uint32_t align)
32 uint32_t offset = batch_used(batch);
33 offset = ALIGN(offset, align);
34 batch->ptr = batch->buffer + offset;
39 batch_alloc(struct intel_batchbuffer *batch, uint32_t size, uint32_t align)
41 uint32_t offset = batch_align(batch, align);
43 return memset(batch->buffer + offset, 0, size);
47 batch_offset(struct intel_batchbuffer *batch, void *ptr)
49 return (uint8_t *)ptr - batch->buffer;
53 batch_copy(struct intel_batchbuffer *batch, const void *ptr, uint32_t size, uint32_t align)
55 return batch_offset(batch, memcpy(batch_alloc(batch, size, align), ptr, size));
59 gen8_render_flush(struct intel_batchbuffer *batch, uint32_t batch_end)
63 ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
65 ret = drm_intel_bo_mrb_exec(batch->bo, batch_end,
71 gen8_fill_curbe_buffer_data(struct intel_batchbuffer *batch,
74 uint8_t *curbe_buffer;
77 curbe_buffer = batch_alloc(batch, sizeof(uint32_t) * 8, 64);
78 offset = batch_offset(batch, curbe_buffer);
79 *curbe_buffer = color;
85 gen8_fill_surface_state(struct intel_batchbuffer *batch,
90 struct gen8_surface_state *ss;
91 uint32_t write_domain, read_domain, offset;
95 write_domain = read_domain = I915_GEM_DOMAIN_RENDER;
98 read_domain = I915_GEM_DOMAIN_SAMPLER;
101 ss = batch_alloc(batch, sizeof(*ss), 64);
102 offset = batch_offset(batch, ss);
104 ss->ss0.surface_type = GEN8_SURFACE_2D;
105 ss->ss0.surface_format = format;
106 ss->ss0.render_cache_read_write = 1;
107 ss->ss0.vertical_alignment = 1; /* align 4 */
108 ss->ss0.horizontal_alignment = 1; /* align 4 */
110 if (buf->tiling == I915_TILING_X)
111 ss->ss0.tiled_mode = 2;
112 else if (buf->tiling == I915_TILING_Y)
113 ss->ss0.tiled_mode = 3;
115 ss->ss8.base_addr = buf->bo->offset;
117 ret = drm_intel_bo_emit_reloc(batch->bo,
118 batch_offset(batch, ss) + 8 * 4,
120 read_domain, write_domain);
123 ss->ss2.height = igt_buf_height(buf) - 1;
124 ss->ss2.width = igt_buf_width(buf) - 1;
125 ss->ss3.pitch = buf->stride - 1;
127 ss->ss7.shader_chanel_select_r = 4;
128 ss->ss7.shader_chanel_select_g = 5;
129 ss->ss7.shader_chanel_select_b = 6;
130 ss->ss7.shader_chanel_select_a = 7;
136 gen8_fill_binding_table(struct intel_batchbuffer *batch,
139 uint32_t *binding_table, offset;
141 binding_table = batch_alloc(batch, 32, 64);
142 offset = batch_offset(batch, binding_table);
144 binding_table[0] = gen8_fill_surface_state(batch, dst, GEN8_SURFACEFORMAT_R8_UNORM, 1);
150 gen8_fill_media_kernel(struct intel_batchbuffer *batch,
151 const uint32_t kernel[][4],
156 offset = batch_copy(batch, kernel, size, 64);
162 gen8_fill_interface_descriptor(struct intel_batchbuffer *batch, struct igt_buf *dst)
164 struct gen8_interface_descriptor_data *idd;
166 uint32_t binding_table_offset, kernel_offset;
168 binding_table_offset = gen8_fill_binding_table(batch, dst);
169 kernel_offset = gen8_fill_media_kernel(batch, media_kernel, sizeof(media_kernel));
171 idd = batch_alloc(batch, sizeof(*idd), 64);
172 offset = batch_offset(batch, idd);
174 idd->desc0.kernel_start_pointer = (kernel_offset >> 6);
176 idd->desc2.single_program_flow = 1;
177 idd->desc2.floating_point_mode = GEN8_FLOATING_POINT_IEEE_754;
179 idd->desc3.sampler_count = 0; /* 0 samplers used */
180 idd->desc3.sampler_state_pointer = 0;
182 idd->desc4.binding_table_entry_count = 0;
183 idd->desc4.binding_table_pointer = (binding_table_offset >> 5);
185 idd->desc5.constant_urb_entry_read_offset = 0;
186 idd->desc5.constant_urb_entry_read_length = 1; /* grf 1 */
192 gen8_emit_state_base_address(struct intel_batchbuffer *batch)
194 OUT_BATCH(GEN8_STATE_BASE_ADDRESS | (16 - 2));
197 OUT_BATCH(0 | BASE_ADDRESS_MODIFY);
200 /* stateless data port */
201 OUT_BATCH(0 | BASE_ADDRESS_MODIFY);
204 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_SAMPLER, 0, BASE_ADDRESS_MODIFY);
208 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION,
209 0, BASE_ADDRESS_MODIFY);
217 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
220 /* general state buffer size */
221 OUT_BATCH(0xfffff000 | 1);
222 /* dynamic state buffer size */
223 OUT_BATCH(1 << 12 | 1);
224 /* indirect object buffer size */
225 OUT_BATCH(0xfffff000 | 1);
226 /* intruction buffer size, must set modify enable bit, otherwise it may result in GPU hang */
227 OUT_BATCH(1 << 12 | 1);
231 gen8_emit_vfe_state(struct intel_batchbuffer *batch)
233 OUT_BATCH(GEN8_MEDIA_VFE_STATE | (9 - 2));
239 /* number of threads & urb entries */
245 /* urb entry size & curbe size */
256 gen8_emit_curbe_load(struct intel_batchbuffer *batch, uint32_t curbe_buffer)
258 OUT_BATCH(GEN8_MEDIA_CURBE_LOAD | (4 - 2));
260 /* curbe total data length */
262 /* curbe data start address, is relative to the dynamics base address */
263 OUT_BATCH(curbe_buffer);
267 gen8_emit_interface_descriptor_load(struct intel_batchbuffer *batch, uint32_t interface_descriptor)
269 OUT_BATCH(GEN8_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
271 /* interface descriptor data length */
272 OUT_BATCH(sizeof(struct gen8_interface_descriptor_data));
273 /* interface descriptor address, is relative to the dynamics base address */
274 OUT_BATCH(interface_descriptor);
278 gen8_emit_media_state_flush(struct intel_batchbuffer *batch)
280 OUT_BATCH(GEN8_MEDIA_STATE_FLUSH | (2 - 2));
285 gen8_emit_media_objects(struct intel_batchbuffer *batch,
286 unsigned x, unsigned y,
287 unsigned width, unsigned height)
291 for (i = 0; i < width / 16; i++) {
292 for (j = 0; j < height / 16; j++) {
293 OUT_BATCH(GEN8_MEDIA_OBJECT | (8 - 2));
295 /* interface descriptor offset */
298 /* without indirect data */
306 /* inline data (xoffset, yoffset) */
307 OUT_BATCH(x + i * 16);
308 OUT_BATCH(y + j * 16);
309 gen8_emit_media_state_flush(batch);
315 * This sets up the media pipeline,
317 * +---------------+ <---- 4096
323 * |_______|_______| <---- 2048 + ?
330 * +---------------+ <---- 0 + ?
334 #define BATCH_STATE_SPLIT 2048
337 gen8_media_fillfunc(struct intel_batchbuffer *batch,
339 unsigned x, unsigned y,
340 unsigned width, unsigned height,
343 uint32_t curbe_buffer, interface_descriptor;
346 intel_batchbuffer_flush(batch);
349 batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
351 curbe_buffer = gen8_fill_curbe_buffer_data(batch, color);
352 interface_descriptor = gen8_fill_interface_descriptor(batch, dst);
353 assert(batch->ptr < &batch->buffer[4095]);
356 batch->ptr = batch->buffer;
357 OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
358 gen8_emit_state_base_address(batch);
360 gen8_emit_vfe_state(batch);
362 gen8_emit_curbe_load(batch, curbe_buffer);
364 gen8_emit_interface_descriptor_load(batch, interface_descriptor);
366 gen8_emit_media_objects(batch, x, y, width, height);
368 OUT_BATCH(MI_BATCH_BUFFER_END);
370 batch_end = batch_align(batch, 8);
371 assert(batch_end < BATCH_STATE_SPLIT);
373 gen8_render_flush(batch, batch_end);
374 intel_batchbuffer_reset(batch);