media_fill.c 11.5 KB
Newer Older
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
/*
 * 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 (including the next
 * paragraph) 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.
 *
 */

#include <intel_bufmgr.h>
#include <i915_drm.h>

#include "media_fill.h"
#include "gen7_media.h"
#include "gen8_media.h"
#include "intel_reg.h"
#include "drmtest.h"
#include "gpu_cmds.h"
#include <assert.h>

static const uint32_t gen7_media_kernel[][4] = {
	{ 0x00400001, 0x20200231, 0x00000020, 0x00000000 },
	{ 0x00600001, 0x20800021, 0x008d0000, 0x00000000 },
	{ 0x00200001, 0x20800021, 0x00450040, 0x00000000 },
	{ 0x00000001, 0x20880061, 0x00000000, 0x000f000f },
	{ 0x00800001, 0x20a00021, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x20e00021, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x21200021, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x21600021, 0x00000020, 0x00000000 },
	{ 0x05800031, 0x24001ca8, 0x00000080, 0x120a8000 },
	{ 0x00600001, 0x2e000021, 0x008d0000, 0x00000000 },
	{ 0x07800031, 0x20001ca8, 0x00000e00, 0x82000010 },
};

static const uint32_t gen8_media_kernel[][4] = {
	{ 0x00400001, 0x20202288, 0x00000020, 0x00000000 },
	{ 0x00600001, 0x20800208, 0x008d0000, 0x00000000 },
	{ 0x00200001, 0x20800208, 0x00450040, 0x00000000 },
	{ 0x00000001, 0x20880608, 0x00000000, 0x000f000f },
	{ 0x00800001, 0x20a00208, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x20e00208, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x21200208, 0x00000020, 0x00000000 },
	{ 0x00800001, 0x21600208, 0x00000020, 0x00000000 },
	{ 0x0c800031, 0x24000a40, 0x0e000080, 0x120a8000 },
	{ 0x00600001, 0x2e000208, 0x008d0000, 0x00000000 },
	{ 0x07800031, 0x20000a40, 0x0e000e00, 0x82000010 },
};

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
static const uint32_t gen11_media_vme_kernel[][4] = {
	{ 0x00600001, 0x20302e68,  0x00000000,  0x20000000 },
	{ 0x00600001, 0x22802e68,  0x00000000,  0x00000001 },
	{ 0x00000001, 0x20284f2c,  0x00000000,  0x3818000c },
	{ 0x00600001, 0x22902e68,  0x00000000,  0x00000010 },
	{ 0x00600001, 0x22a02e68,  0x00000000,  0x00010000 },
	{ 0x00000001, 0x202c4f2c,  0x00000000,  0x22222222 },
	{ 0x00000040, 0x22000a20,  0x0e000020,  0x10782000 },
	{ 0x00600001, 0x20404f28,  0x00000000,  0x00000000 },
	{ 0x00600001, 0x20a04f28,  0x00000000,  0x00000000 },
	{ 0x00600001, 0x20c04f28,  0x00000000,  0x00000000 },
	{ 0x00600001, 0x21204f28,  0x00000000,  0x00000000 },
	{ 0x00600001, 0x20601a28,  0x008d0030,  0x00000000 },
	{ 0x00600041, 0x20800a28,  0x1a000028,  0x008d0280 },
	{ 0x00600041, 0x20e01a28,  0x1e8d0290,  0x01000100 },
	{ 0x00600041, 0x21000a28,  0x1a00002c,  0x008d02a0 },
	{ 0x00000001, 0x22284f2c,  0x00000000,  0x00000000 },
	{ 0x0d80c031, 0x21404a48,  0x00000040,  0x00000200 },
	{ 0x00000001, 0x215c4708,  0x00000000,  0xbeefbeef },
	{ 0x00000040, 0x22000204,  0x06000024,  0x020a0400 },
	{ 0x00000001, 0x215e4708,  0x00000000,  0xdeaddead },
	{ 0x00000001, 0x22484f2c,  0x00000000,  0x00000008 },
	{ 0x00000001, 0x22684f2c,  0x00000000,  0x0000000c },
	{ 0x00600001, 0x2fe04b2c,  0x008d0000,  0x00000000 },
	{ 0x0a800033, 0x0000a054,  0x00002224,  0x00000000 },
	{ 0x00000040, 0x22000204,  0x06000024,  0x020a0300 },
	{ 0x0a800033, 0x0000e054,  0x00002242,  0x00000000 },
	{ 0x00000040, 0x22000204,  0x06000024,  0x020a0200 },
	{ 0x0a600033, 0x00010014,  0x00002261,  0x00000000 },
	{ 0x07600031, 0x20004a04,  0x06000fe0,  0x82000010 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
	{ 0x00000000, 0x00000000,  0x00000000,  0x00000000 },
};

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
/*
 * This sets up the media pipeline,
 *
 * +---------------+ <---- 4096
 * |       ^       |
 * |       |       |
 * |    various    |
 * |      state    |
 * |       |       |
 * |_______|_______| <---- 2048 + ?
 * |       ^       |
 * |       |       |
 * |   batch       |
 * |    commands   |
 * |       |       |
 * |       |       |
 * +---------------+ <---- 0 + ?
 *
 */

#define BATCH_STATE_SPLIT 2048
/* VFE STATE params */
#define THREADS 1
#define MEDIA_URB_ENTRIES 2
#define MEDIA_URB_SIZE 2
#define MEDIA_CURBE_SIZE 2
#define GEN7_VFE_STATE_MEDIA_MODE 0

void
gen7_media_fillfunc(struct intel_batchbuffer *batch,
Ville Syrjälä's avatar
Ville Syrjälä committed
134
		    const struct igt_buf *dst,
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
		    unsigned int x, unsigned int y,
		    unsigned int width, unsigned int height,
		    uint8_t color)
{
	uint32_t curbe_buffer, interface_descriptor;
	uint32_t batch_end;

	intel_batchbuffer_flush(batch);

	/* setup states */
	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];

	curbe_buffer = gen7_fill_curbe_buffer_data(batch, color);
	interface_descriptor = gen7_fill_interface_descriptor(batch, dst,
					gen7_media_kernel,
					sizeof(gen7_media_kernel));
	igt_assert(batch->ptr < &batch->buffer[4095]);

	/* media pipeline */
	batch->ptr = batch->buffer;
	OUT_BATCH(GEN7_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
	gen7_emit_state_base_address(batch);

	gen7_emit_vfe_state(batch, THREADS, MEDIA_URB_ENTRIES, MEDIA_URB_SIZE,
			    MEDIA_CURBE_SIZE, GEN7_VFE_STATE_MEDIA_MODE);;

	gen7_emit_curbe_load(batch, curbe_buffer);

	gen7_emit_interface_descriptor_load(batch, interface_descriptor);

	gen7_emit_media_objects(batch, x, y, width, height);

	OUT_BATCH(MI_BATCH_BUFFER_END);

	batch_end = intel_batchbuffer_align(batch, 8);
	igt_assert(batch_end < BATCH_STATE_SPLIT);

	gen7_render_flush(batch, batch_end);
	intel_batchbuffer_reset(batch);
}

void
gen8_media_fillfunc(struct intel_batchbuffer *batch,
Ville Syrjälä's avatar
Ville Syrjälä committed
178
		    const struct igt_buf *dst,
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
		    unsigned int x, unsigned int y,
		    unsigned int width, unsigned int height,
		    uint8_t color)
{
	uint32_t curbe_buffer, interface_descriptor;
	uint32_t batch_end;

	intel_batchbuffer_flush(batch);

	/* setup states */
	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];

	curbe_buffer = gen7_fill_curbe_buffer_data(batch, color);
	interface_descriptor = gen8_fill_interface_descriptor(batch, dst,
					gen8_media_kernel,
					sizeof(gen8_media_kernel));
	igt_assert(batch->ptr < &batch->buffer[4095]);

	/* media pipeline */
	batch->ptr = batch->buffer;
	OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
	gen8_emit_state_base_address(batch);

	gen8_emit_vfe_state(batch, THREADS, MEDIA_URB_ENTRIES, MEDIA_URB_SIZE,
			    MEDIA_CURBE_SIZE);

	gen7_emit_curbe_load(batch, curbe_buffer);

	gen7_emit_interface_descriptor_load(batch, interface_descriptor);

	gen7_emit_media_objects(batch, x, y, width, height);

	OUT_BATCH(MI_BATCH_BUFFER_END);

	batch_end = intel_batchbuffer_align(batch, 8);
	igt_assert(batch_end < BATCH_STATE_SPLIT);

	gen7_render_flush(batch, batch_end);
	intel_batchbuffer_reset(batch);
}

static void
__gen9_media_fillfunc(struct intel_batchbuffer *batch,
Ville Syrjälä's avatar
Ville Syrjälä committed
222
		      const struct igt_buf *dst,
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
		      unsigned int x, unsigned int y,
		      unsigned int width, unsigned int height,
		      uint8_t color, const uint32_t kernel[][4],
		      size_t kernel_size)
{
	uint32_t curbe_buffer, interface_descriptor;
	uint32_t batch_end;

	intel_batchbuffer_flush(batch);

	/* setup states */
	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];

	curbe_buffer = gen7_fill_curbe_buffer_data(batch, color);
	interface_descriptor = gen8_fill_interface_descriptor(batch, dst,
					kernel, kernel_size);
	assert(batch->ptr < &batch->buffer[4095]);

	/* media pipeline */
	batch->ptr = batch->buffer;
	OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA |
		  GEN9_FORCE_MEDIA_AWAKE_ENABLE |
		  GEN9_SAMPLER_DOP_GATE_DISABLE |
		  GEN9_PIPELINE_SELECTION_MASK |
		  GEN9_SAMPLER_DOP_GATE_MASK |
		  GEN9_FORCE_MEDIA_AWAKE_MASK);
	gen9_emit_state_base_address(batch);

	gen8_emit_vfe_state(batch, THREADS, MEDIA_URB_ENTRIES, MEDIA_URB_SIZE,
			    MEDIA_CURBE_SIZE);

	gen7_emit_curbe_load(batch, curbe_buffer);

	gen7_emit_interface_descriptor_load(batch, interface_descriptor);

	gen7_emit_media_objects(batch, x, y, width, height);

	OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA |
		  GEN9_FORCE_MEDIA_AWAKE_DISABLE |
		  GEN9_SAMPLER_DOP_GATE_ENABLE |
		  GEN9_PIPELINE_SELECTION_MASK |
		  GEN9_SAMPLER_DOP_GATE_MASK |
		  GEN9_FORCE_MEDIA_AWAKE_MASK);

	OUT_BATCH(MI_BATCH_BUFFER_END);

	batch_end = intel_batchbuffer_align(batch, 8);
	assert(batch_end < BATCH_STATE_SPLIT);

	gen7_render_flush(batch, batch_end);
	intel_batchbuffer_reset(batch);
}

void
gen9_media_fillfunc(struct intel_batchbuffer *batch,
Ville Syrjälä's avatar
Ville Syrjälä committed
278
		    const struct igt_buf *dst,
279 280 281 282 283 284 285 286 287
		    unsigned int x, unsigned int y,
		    unsigned int width, unsigned int height,
		    uint8_t color)
{

	__gen9_media_fillfunc(batch, dst, x, y, width, height, color,
			      gen8_media_kernel, sizeof(gen8_media_kernel));

}
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

static void
__gen11_media_vme_func(struct intel_batchbuffer *batch,
		       const struct igt_buf *src,
		       unsigned int width, unsigned int height,
		       const struct igt_buf *dst,
		       const uint32_t kernel[][4],
		       size_t kernel_size)
{
	uint32_t curbe_buffer, interface_descriptor;
	uint32_t batch_end;

	intel_batchbuffer_flush(batch);

	/* setup states */
	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];

	curbe_buffer = gen11_fill_curbe_buffer_data(batch);
	interface_descriptor = gen11_fill_interface_descriptor(batch, src, dst,
					kernel, kernel_size);
	assert(batch->ptr < &batch->buffer[4095]);

	/* media pipeline */
	batch->ptr = batch->buffer;
	OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA |
		  GEN9_FORCE_MEDIA_AWAKE_ENABLE |
		  GEN9_SAMPLER_DOP_GATE_DISABLE |
		  GEN9_PIPELINE_SELECTION_MASK |
		  GEN9_SAMPLER_DOP_GATE_MASK |
		  GEN9_FORCE_MEDIA_AWAKE_MASK);
	gen9_emit_state_base_address(batch);

	gen8_emit_vfe_state(batch, THREADS, MEDIA_URB_ENTRIES, MEDIA_URB_SIZE,
			    MEDIA_CURBE_SIZE);

	gen7_emit_curbe_load(batch, curbe_buffer);

	gen7_emit_interface_descriptor_load(batch, interface_descriptor);

	gen7_emit_media_objects(batch, 0, 0, width, height);

	OUT_BATCH(GEN8_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA |
		  GEN9_FORCE_MEDIA_AWAKE_DISABLE |
		  GEN9_SAMPLER_DOP_GATE_ENABLE |
		  GEN9_PIPELINE_SELECTION_MASK |
		  GEN9_SAMPLER_DOP_GATE_MASK |
		  GEN9_FORCE_MEDIA_AWAKE_MASK);

	OUT_BATCH(MI_BATCH_BUFFER_END);

	batch_end = intel_batchbuffer_align(batch, 8);
	assert(batch_end < BATCH_STATE_SPLIT);

341
	gen7_render_context_flush(batch, batch_end);
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
	intel_batchbuffer_reset(batch);
}

void
gen11_media_vme_func(struct intel_batchbuffer *batch,
		     const struct igt_buf *src,
		     unsigned int width, unsigned int height,
		     const struct igt_buf *dst)
{
	__gen11_media_vme_func(batch,
			       src,
			       width, height,
			       dst,
			       gen11_media_vme_kernel,
			       sizeof(gen11_media_vme_kernel));
}