rendercopy_gen6.c 16.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <assert.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "drm.h"
#include "i915_drm.h"
#include "drmtest.h"
#include "intel_bufmgr.h"
#include "intel_batchbuffer.h"
17
#include "intel_io.h"
18
#include "rendercopy.h"
19
#include "gen6_render.h"
20
#include "intel_reg.h"
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

#define VERTEX_SIZE (3*4)

static const uint32_t ps_kernel_nomask_affine[][4] = {
	{ 0x0060005a, 0x204077be, 0x000000c0, 0x008d0040 },
	{ 0x0060005a, 0x206077be, 0x000000c0, 0x008d0080 },
	{ 0x0060005a, 0x208077be, 0x000000d0, 0x008d0040 },
	{ 0x0060005a, 0x20a077be, 0x000000d0, 0x008d0080 },
	{ 0x00000201, 0x20080061, 0x00000000, 0x00000000 },
	{ 0x00600001, 0x20200022, 0x008d0000, 0x00000000 },
	{ 0x02800031, 0x21c01cc9, 0x00000020, 0x0a8a0001 },
	{ 0x00600001, 0x204003be, 0x008d01c0, 0x00000000 },
	{ 0x00600001, 0x206003be, 0x008d01e0, 0x00000000 },
	{ 0x00600001, 0x208003be, 0x008d0200, 0x00000000 },
	{ 0x00600001, 0x20a003be, 0x008d0220, 0x00000000 },
	{ 0x00600001, 0x20c003be, 0x008d0240, 0x00000000 },
	{ 0x00600001, 0x20e003be, 0x008d0260, 0x00000000 },
	{ 0x00600001, 0x210003be, 0x008d0280, 0x00000000 },
	{ 0x00600001, 0x212003be, 0x008d02a0, 0x00000000 },
	{ 0x05800031, 0x24001cc8, 0x00000040, 0x90019000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
	{ 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
};

static uint32_t
52
batch_round_upto(struct intel_batchbuffer *batch, uint32_t divisor)
53
{
54 55
	uint32_t offset = batch->ptr - batch->buffer;

56
	offset = (offset + divisor-1) / divisor * divisor;
57 58 59 60 61
	batch->ptr = batch->buffer + offset;
	return offset;
}

static void
62 63
gen6_render_flush(struct intel_batchbuffer *batch,
		  drm_intel_context *context, uint32_t batch_end)
64 65 66 67 68
{
	int ret;

	ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
	if (ret == 0)
69 70
		ret = drm_intel_gem_bo_context_exec(batch->bo, context,
						    batch_end, 0);
71
	igt_assert(ret == 0);
72 73 74
}

static uint32_t
Ville Syrjälä's avatar
Ville Syrjälä committed
75
gen6_bind_buf(struct intel_batchbuffer *batch, const struct igt_buf *buf,
76
	      int is_dst)
77 78 79 80 81 82 83 84 85 86 87 88
{
	struct gen6_surface_state *ss;
	uint32_t write_domain, read_domain;
	int ret;

	if (is_dst) {
		write_domain = read_domain = I915_GEM_DOMAIN_RENDER;
	} else {
		write_domain = 0;
		read_domain = I915_GEM_DOMAIN_SAMPLER;
	}

89
	ss = intel_batchbuffer_subdata_alloc(batch, sizeof(*ss), 32);
90
	ss->ss0.surface_type = SURFACE_2D;
91 92 93 94 95 96 97

	switch (buf->bpp) {
		case 8: ss->ss0.surface_format = SURFACEFORMAT_R8_UNORM; break;
		case 16: ss->ss0.surface_format = SURFACEFORMAT_R8G8_UNORM; break;
		case 32: ss->ss0.surface_format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
		default: igt_assert(0);
	}
98

99
	ss->ss0.data_return_format = SURFACERETURNFORMAT_FLOAT32;
100 101 102 103
	ss->ss0.color_blend = 1;
	ss->ss1.base_addr = buf->bo->offset;

	ret = drm_intel_bo_emit_reloc(batch->bo,
104
				      intel_batchbuffer_subdata_offset(batch, &ss->ss1),
105 106
				      buf->bo, 0,
				      read_domain, write_domain);
107
	igt_assert(ret == 0);
108

109 110
	ss->ss2.height = igt_buf_height(buf) - 1;
	ss->ss2.width  = igt_buf_width(buf) - 1;
111 112 113 114
	ss->ss3.pitch  = buf->stride - 1;
	ss->ss3.tiled_surface = buf->tiling != I915_TILING_NONE;
	ss->ss3.tile_walk     = buf->tiling == I915_TILING_Y;

115
	return intel_batchbuffer_subdata_offset(batch, ss);
116 117 118
}

static uint32_t
119
gen6_bind_surfaces(struct intel_batchbuffer *batch,
Ville Syrjälä's avatar
Ville Syrjälä committed
120 121
		   const struct igt_buf *src,
		   const struct igt_buf *dst)
122 123 124
{
	uint32_t *binding_table;

125
	binding_table = intel_batchbuffer_subdata_alloc(batch, 32, 32);
126

127 128
	binding_table[0] = gen6_bind_buf(batch, dst, 1);
	binding_table[1] = gen6_bind_buf(batch, src, 0);
129

130
	return intel_batchbuffer_subdata_offset(batch, binding_table);
131 132 133
}

static void
134
gen6_emit_sip(struct intel_batchbuffer *batch)
135
{
136
	OUT_BATCH(GEN4_STATE_SIP | 0);
137 138 139 140
	OUT_BATCH(0);
}

static void
141
gen6_emit_urb(struct intel_batchbuffer *batch)
142 143 144 145 146 147 148 149 150
{
	OUT_BATCH(GEN6_3DSTATE_URB | (3 - 2));
	OUT_BATCH((1 - 1) << GEN6_3DSTATE_URB_VS_SIZE_SHIFT |
		  24 << GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT); /* at least 24 on GEN6 */
	OUT_BATCH(0 << GEN6_3DSTATE_URB_GS_SIZE_SHIFT |
		  0 << GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT); /* no GS thread */
}

static void
151
gen6_emit_state_base_address(struct intel_batchbuffer *batch)
152
{
153
	OUT_BATCH(GEN4_STATE_BASE_ADDRESS | (10 - 2));
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
	OUT_BATCH(0); /* general */
	OUT_RELOC(batch->bo, /* surface */
		  I915_GEM_DOMAIN_INSTRUCTION, 0,
		  BASE_ADDRESS_MODIFY);
	OUT_RELOC(batch->bo, /* instruction */
		  I915_GEM_DOMAIN_INSTRUCTION, 0,
		  BASE_ADDRESS_MODIFY);
	OUT_BATCH(0); /* indirect */
	OUT_RELOC(batch->bo, /* dynamic */
		  I915_GEM_DOMAIN_INSTRUCTION, 0,
		  BASE_ADDRESS_MODIFY);

	/* upper bounds, disable */
	OUT_BATCH(0);
	OUT_BATCH(BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);
	OUT_BATCH(BASE_ADDRESS_MODIFY);
}

static void
174
gen6_emit_viewports(struct intel_batchbuffer *batch, uint32_t cc_vp)
175 176 177 178 179 180 181 182 183 184
{
	OUT_BATCH(GEN6_3DSTATE_VIEWPORT_STATE_POINTERS |
		  GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC |
		  (4 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(cc_vp);
}

static void
185
gen6_emit_vs(struct intel_batchbuffer *batch)
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
{
	/* disable VS constant buffer */
	OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | (5 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);

	OUT_BATCH(GEN6_3DSTATE_VS | (6 - 2));
	OUT_BATCH(0); /* no VS kernel */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); /* pass-through */
}

static void
203
gen6_emit_gs(struct intel_batchbuffer *batch)
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
{
	/* disable GS constant buffer */
	OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (5 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);

	OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
	OUT_BATCH(0); /* no GS kernel */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); /* pass-through */
}

static void
222
gen6_emit_clip(struct intel_batchbuffer *batch)
223 224 225 226 227 228 229 230
{
	OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0); /* pass-through */
	OUT_BATCH(0);
}

static void
231
gen6_emit_wm_constants(struct intel_batchbuffer *batch)
232 233 234 235 236 237 238 239 240 241
{
	/* disable WM constant buffer */
	OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | (5 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
}

static void
242
gen6_emit_null_depth_buffer(struct intel_batchbuffer *batch)
243
{
244 245 246
	OUT_BATCH(GEN4_3DSTATE_DEPTH_BUFFER | (7 - 2));
	OUT_BATCH(SURFACE_NULL << GEN4_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT |
		  GEN4_DEPTHFORMAT_D32_FLOAT << GEN4_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT);
247 248 249 250 251 252
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);

253
	OUT_BATCH(GEN4_3DSTATE_CLEAR_PARAMS | (2 - 2));
254 255 256 257
	OUT_BATCH(0);
}

static void
258
gen6_emit_invariant(struct intel_batchbuffer *batch)
259
{
260
	OUT_BATCH(G4X_PIPELINE_SELECT | PIPELINE_SELECT_3D);
261 262 263 264 265 266 267 268 269 270 271

	OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE | (3 - 2));
	OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
		  GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
	OUT_BATCH(0);

	OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK | (2 - 2));
	OUT_BATCH(1);
}

static void
272
gen6_emit_cc(struct intel_batchbuffer *batch, uint32_t blend)
273 274 275 276 277 278 279 280
{
	OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (4 - 2));
	OUT_BATCH(blend | 1);
	OUT_BATCH(1024 | 1);
	OUT_BATCH(1024 | 1);
}

static void
281
gen6_emit_sampler(struct intel_batchbuffer *batch, uint32_t state)
282 283 284 285 286 287 288 289 290 291
{
	OUT_BATCH(GEN6_3DSTATE_SAMPLER_STATE_POINTERS |
		  GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS |
		  (4 - 2));
	OUT_BATCH(0); /* VS */
	OUT_BATCH(0); /* GS */
	OUT_BATCH(state);
}

static void
292
gen6_emit_sf(struct intel_batchbuffer *batch)
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
{
	OUT_BATCH(GEN6_3DSTATE_SF | (20 - 2));
	OUT_BATCH(1 << GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT |
		  1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT |
		  1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT);
	OUT_BATCH(0);
	OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
	OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT); /* DW4 */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); /* DW9 */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); /* DW14 */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); /* DW19 */
}

static void
319
gen6_emit_wm(struct intel_batchbuffer *batch, int kernel)
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
{
	OUT_BATCH(GEN6_3DSTATE_WM | (9 - 2));
	OUT_BATCH(kernel);
	OUT_BATCH(1 << GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT |
		  2 << GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT);
	OUT_BATCH(0);
	OUT_BATCH(6 << GEN6_3DSTATE_WM_DISPATCH_START_GRF_0_SHIFT); /* DW4 */
	OUT_BATCH((40 - 1) << GEN6_3DSTATE_WM_MAX_THREADS_SHIFT |
		  GEN6_3DSTATE_WM_DISPATCH_ENABLE |
		  GEN6_3DSTATE_WM_16_DISPATCH_ENABLE);
	OUT_BATCH(1 << GEN6_3DSTATE_WM_NUM_SF_OUTPUTS_SHIFT |
		  GEN6_3DSTATE_WM_PERSPECTIVE_PIXEL_BARYCENTRIC);
	OUT_BATCH(0);
	OUT_BATCH(0);
}

static void
337
gen6_emit_binding_table(struct intel_batchbuffer *batch, uint32_t wm_table)
338
{
339
	OUT_BATCH(GEN4_3DSTATE_BINDING_TABLE_POINTERS |
340 341 342 343 344 345 346 347
		  GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS |
		  (4 - 2));
	OUT_BATCH(0);		/* vs */
	OUT_BATCH(0);		/* gs */
	OUT_BATCH(wm_table);
}

static void
Ville Syrjälä's avatar
Ville Syrjälä committed
348
gen6_emit_drawing_rectangle(struct intel_batchbuffer *batch, const struct igt_buf *dst)
349
{
350
	OUT_BATCH(GEN4_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
351
	OUT_BATCH(0);
352
	OUT_BATCH((igt_buf_height(dst) - 1) << 16 | (igt_buf_width(dst) - 1));
353 354 355 356
	OUT_BATCH(0);
}

static void
357
gen6_emit_vertex_elements(struct intel_batchbuffer *batch)
358 359 360 361 362 363 364 365
{
	/* The VUE layout
	 *    dword 0-3: pad (0.0, 0.0, 0.0. 0.0)
	 *    dword 4-7: position (x, y, 1.0, 1.0),
	 *    dword 8-11: texture coordinate 0 (u0, v0, 0, 0)
	 *
	 * dword 4-11 are fetched from vertex buffer
	 */
366
	OUT_BATCH(GEN4_3DSTATE_VERTEX_ELEMENTS | (2 * 3 + 1 - 2));
367

368
	OUT_BATCH(0 << GEN6_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN6_VE0_VALID |
369
		  SURFACEFORMAT_R32G32B32A32_FLOAT << VE0_FORMAT_SHIFT |
370
		  0 << VE0_OFFSET_SHIFT);
371 372 373 374
	OUT_BATCH(GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_0_SHIFT |
		  GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT |
		  GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
		  GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT);
375 376

	/* x,y */
377
	OUT_BATCH(0 << GEN6_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN6_VE0_VALID |
378
		  SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
379
		  0 << VE0_OFFSET_SHIFT); /* offsets vb in bytes */
380 381 382 383
	OUT_BATCH(GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
		  GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
		  GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_2_SHIFT |
		  GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
384 385

	/* u0, v0 */
386
	OUT_BATCH(0 << GEN6_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN6_VE0_VALID |
387
		  SURFACEFORMAT_R32G32_FLOAT << VE0_FORMAT_SHIFT |
388
		  4 << VE0_OFFSET_SHIFT);	/* offset vb in bytes */
389 390 391 392
	OUT_BATCH(GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
		  GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
		  GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
		  GEN4_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT);
393 394 395
}

static uint32_t
396
gen6_create_cc_viewport(struct intel_batchbuffer *batch)
397
{
398
	struct gen4_cc_viewport *vp;
399

400
	vp = intel_batchbuffer_subdata_alloc(batch, sizeof(*vp), 32);
401 402 403 404

	vp->min_depth = -1.e35;
	vp->max_depth = 1.e35;

405
	return intel_batchbuffer_subdata_offset(batch, vp);
406 407 408
}

static uint32_t
409
gen6_create_cc_blend(struct intel_batchbuffer *batch)
410 411 412
{
	struct gen6_blend_state *blend;

413
	blend = intel_batchbuffer_subdata_alloc(batch, sizeof(*blend), 64);
414 415 416 417 418 419 420 421 422

	blend->blend0.dest_blend_factor = GEN6_BLENDFACTOR_ZERO;
	blend->blend0.source_blend_factor = GEN6_BLENDFACTOR_ONE;
	blend->blend0.blend_func = GEN6_BLENDFUNCTION_ADD;
	blend->blend0.blend_enable = 1;

	blend->blend1.post_blend_clamp_enable = 1;
	blend->blend1.pre_blend_clamp_enable = 1;

423
	return intel_batchbuffer_subdata_offset(batch, blend);
424 425 426
}

static uint32_t
427
gen6_create_kernel(struct intel_batchbuffer *batch)
428
{
429
	return intel_batchbuffer_copy_data(batch, ps_kernel_nomask_affine,
430 431 432 433 434
			  sizeof(ps_kernel_nomask_affine),
			  64);
}

static uint32_t
435 436
gen6_create_sampler(struct intel_batchbuffer *batch,
		    sampler_filter_t filter,
437 438 439 440
		   sampler_extend_t extend)
{
	struct gen6_sampler_state *ss;

441
	ss = intel_batchbuffer_subdata_alloc(batch, sizeof(*ss), 32);
442 443 444 445
	ss->ss0.lod_preclamp = 1;	/* GL mode */

	/* We use the legacy mode to get the semantics specified by
	 * the Render extension. */
446
	ss->ss0.border_color_mode = GEN4_BORDER_COLOR_MODE_LEGACY;
447 448 449 450

	switch (filter) {
	default:
	case SAMPLER_FILTER_NEAREST:
451 452
		ss->ss0.min_filter = GEN4_MAPFILTER_NEAREST;
		ss->ss0.mag_filter = GEN4_MAPFILTER_NEAREST;
453 454
		break;
	case SAMPLER_FILTER_BILINEAR:
455 456
		ss->ss0.min_filter = GEN4_MAPFILTER_LINEAR;
		ss->ss0.mag_filter = GEN4_MAPFILTER_LINEAR;
457 458 459 460 461 462
		break;
	}

	switch (extend) {
	default:
	case SAMPLER_EXTEND_NONE:
463 464 465
		ss->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
		ss->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
		ss->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
466 467
		break;
	case SAMPLER_EXTEND_REPEAT:
468 469 470
		ss->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
		ss->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
		ss->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
471 472
		break;
	case SAMPLER_EXTEND_PAD:
473 474 475
		ss->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
		ss->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
		ss->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
476 477
		break;
	case SAMPLER_EXTEND_REFLECT:
478 479 480
		ss->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
		ss->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
		ss->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
481 482 483
		break;
	}

484
	return intel_batchbuffer_subdata_offset(batch, ss);
485 486
}

487
static void gen6_emit_vertex_buffer(struct intel_batchbuffer *batch)
488
{
489 490 491
	OUT_BATCH(GEN4_3DSTATE_VERTEX_BUFFERS | 3);
	OUT_BATCH(GEN6_VB0_VERTEXDATA |
		  0 << GEN6_VB0_BUFFER_INDEX_SHIFT |
492 493 494 495 496 497
		  VERTEX_SIZE << VB0_BUFFER_PITCH_SHIFT);
	OUT_RELOC(batch->bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
	OUT_RELOC(batch->bo, I915_GEM_DOMAIN_VERTEX, 0, batch->bo->size-1);
	OUT_BATCH(0);
}

498
static uint32_t gen6_emit_primitive(struct intel_batchbuffer *batch)
499 500 501
{
	uint32_t offset;

502 503 504
	OUT_BATCH(GEN4_3DPRIMITIVE |
		  GEN4_3DPRIMITIVE_VERTEX_SEQUENTIAL |
		  _3DPRIM_RECTLIST << GEN4_3DPRIMITIVE_TOPOLOGY_SHIFT |
505 506 507
		  0 << 9 |
		  4);
	OUT_BATCH(3);	/* vertex count */
508
	offset = batch->ptr - batch->buffer;
509 510 511 512 513 514 515 516
	OUT_BATCH(0);	/* vertex_index */
	OUT_BATCH(1);	/* single instance */
	OUT_BATCH(0);	/* start instance location */
	OUT_BATCH(0);	/* index buffer offset, ignored */

	return offset;
}

517
void gen6_render_copyfunc(struct intel_batchbuffer *batch,
518
			  drm_intel_context *context,
Ville Syrjälä's avatar
Ville Syrjälä committed
519
			  const struct igt_buf *src, unsigned src_x, unsigned src_y,
520
			  unsigned width, unsigned height,
Ville Syrjälä's avatar
Ville Syrjälä committed
521
			  const struct igt_buf *dst, unsigned dst_x, unsigned dst_y)
522 523 524 525 526
{
	uint32_t wm_state, wm_kernel, wm_table;
	uint32_t cc_vp, cc_blend, offset;
	uint32_t batch_end;

527
	igt_assert(src->bpp == dst->bpp);
528
	intel_batchbuffer_flush_with_context(batch, context);
529 530

	batch->ptr = batch->buffer + 1024;
531
	intel_batchbuffer_subdata_alloc(batch, 64, 64);
532 533 534 535
	wm_table  = gen6_bind_surfaces(batch, src, dst);
	wm_kernel = gen6_create_kernel(batch);
	wm_state  = gen6_create_sampler(batch,
					SAMPLER_FILTER_NEAREST,
536 537
					SAMPLER_EXTEND_NONE);

538 539
	cc_vp = gen6_create_cc_viewport(batch);
	cc_blend = gen6_create_cc_blend(batch);
540 541 542

	batch->ptr = batch->buffer;

543 544
	gen6_emit_invariant(batch);
	gen6_emit_state_base_address(batch);
545

546 547
	gen6_emit_sip(batch);
	gen6_emit_urb(batch);
548

549 550 551 552 553 554
	gen6_emit_viewports(batch, cc_vp);
	gen6_emit_vs(batch);
	gen6_emit_gs(batch);
	gen6_emit_clip(batch);
	gen6_emit_wm_constants(batch);
	gen6_emit_null_depth_buffer(batch);
555

556 557 558 559 560 561 562
	gen6_emit_drawing_rectangle(batch, dst);
	gen6_emit_cc(batch, cc_blend);
	gen6_emit_sampler(batch, wm_state);
	gen6_emit_sf(batch);
	gen6_emit_wm(batch, wm_kernel);
	gen6_emit_vertex_elements(batch);
	gen6_emit_binding_table(batch, wm_table);
563

564 565
	gen6_emit_vertex_buffer(batch);
	offset = gen6_emit_primitive(batch);
566 567

	OUT_BATCH(MI_BATCH_BUFFER_END);
568
	batch_end = intel_batchbuffer_align(batch, 8);
569 570

	*(uint32_t*)(batch->buffer + offset) =
571
		batch_round_upto(batch, VERTEX_SIZE)/VERTEX_SIZE;
572

573
	emit_vertex_2s(batch, dst_x + width, dst_y + height);
574 575
	emit_vertex_normalized(batch, src_x + width, igt_buf_width(src));
	emit_vertex_normalized(batch, src_y + height, igt_buf_height(src));
576

577
	emit_vertex_2s(batch, dst_x, dst_y + height);
578 579
	emit_vertex_normalized(batch, src_x, igt_buf_width(src));
	emit_vertex_normalized(batch, src_y + height, igt_buf_height(src));
580

581
	emit_vertex_2s(batch, dst_x, dst_y);
582 583
	emit_vertex_normalized(batch, src_x, igt_buf_width(src));
	emit_vertex_normalized(batch, src_y, igt_buf_height(src));
584

585
	gen6_render_flush(batch, context, batch_end);
586 587
	intel_batchbuffer_reset(batch);
}