summaryrefslogtreecommitdiff
path: root/tools/null_state_gen/intel_renderstate_gen9.c
blob: 3701acd1cd1c827bf4a785eda869cb83ee8f994e (plain)
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
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
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
134
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
178
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
222
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
278
279
280
281
282
283
284
285
286
287
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/*
 * Copyright © 2014 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.
 *
 * Authors:
 *	Armin Reese <armin.c.reese@intel.com>
 *	Mika Kuoppala <mika.kuoppala@intel.com>
 */

#include "intel_renderstate.h"
#include <lib/gen9_render.h>
#include <lib/intel_reg.h>

static void gen8_emit_wm(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN6_3DSTATE_WM | (2 - 2));
	OUT_BATCH(GEN8_WM_LEGACY_DIAMOND_LINE_RASTERIZATION);
}

static void gen8_emit_ps(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN7_3DSTATE_PS | (12 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0); /* kernel hi */
	OUT_BATCH(GEN7_PS_SPF_MODE);
	OUT_BATCH(0); /* scratch space stuff */
	OUT_BATCH(0); /* scratch hi */
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0); // kernel 1
	OUT_BATCH(0); /* kernel 1 hi */
	OUT_BATCH(0); // kernel 2
	OUT_BATCH(0); /* kernel 2 hi */
}

static void gen8_emit_sf(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN6_3DSTATE_SF | (4 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(1 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT |
		  1 << GEN6_3DSTATE_SF_VERTEX_SUB_PIXEL_PRECISION_SHIFT |
		  GEN8_SF_POINT_WIDTH_FROM_SOURCE |
		  8);
}

static void gen8_emit_vs(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN6_3DSTATE_VS | (9 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(GEN8_VS_FLOATING_POINT_MODE_ALTERNATE);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
}

static void gen8_emit_hs(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN7_3DSTATE_HS | (9 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(1 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT);
	OUT_BATCH(0);
}

static void gen8_emit_raster(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN8_3DSTATE_RASTER | (5 - 2));
	OUT_BATCH(0);
	OUT_BATCH(0.0);
	OUT_BATCH(0.0);
	OUT_BATCH(0.0);
}

static void gen8_emit_urb(struct intel_batchbuffer *batch)
{
	const int vs_entries = 64;
	const int vs_size = 2;
	const int vs_start = 4;

	OUT_BATCH(GEN7_3DSTATE_URB_VS);
	OUT_BATCH(vs_entries | ((vs_size - 1) << 16) | (vs_start << 25));

	OUT_BATCH(GEN7_3DSTATE_URB_HS);
	OUT_BATCH(0x0f << 25);

	OUT_BATCH(GEN7_3DSTATE_URB_DS);
	OUT_BATCH(0x0f << 25);

	OUT_BATCH(GEN7_3DSTATE_URB_GS);
	OUT_BATCH(0x0f << 25);
}

static void gen8_emit_vf_topology(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN8_3DSTATE_VF_TOPOLOGY);
	OUT_BATCH(_3DPRIM_TRILIST);
}

static void gen8_emit_so_decl_list(struct intel_batchbuffer *batch)
{
	const int num_decls = 128;
	int i;

	OUT_BATCH(GEN8_3DSTATE_SO_DECL_LIST |
		(((2 * num_decls) + 3) - 2) /* DWORD count - 2 */);
	OUT_BATCH(0);
	OUT_BATCH(num_decls);

	for (i = 0; i < num_decls; i++) {
		OUT_BATCH(0);
		OUT_BATCH(0);
	}
}

static void gen8_emit_so_buffer(struct intel_batchbuffer *batch, const int index)
{
	OUT_BATCH(GEN8_3DSTATE_SO_BUFFER | (8 - 2));
	OUT_BATCH(index << 29);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
}

static void gen8_emit_chroma_key(struct intel_batchbuffer *batch, const int index)
{
	OUT_BATCH(GEN6_3DSTATE_CHROMA_KEY | (4 - 2));
	OUT_BATCH(index << 30);
	OUT_BATCH(0);
	OUT_BATCH(0);
}

static void gen8_emit_vertex_buffers(struct intel_batchbuffer *batch)
{
	const int buffers = 33;
	int i;

	OUT_BATCH(GEN4_3DSTATE_VERTEX_BUFFERS |
		(((4 * buffers) + 1)- 2) /* DWORD count - 2 */);

	for (i = 0; i < buffers; i++) {
		OUT_BATCH(i << GEN6_VB0_BUFFER_INDEX_SHIFT |
			  GEN8_VB0_BUFFER_ADDR_MOD_EN);
		OUT_BATCH(0); /* Address */
		OUT_BATCH(0);
		OUT_BATCH(0);
	}
}

static void gen8_emit_vertex_elements(struct intel_batchbuffer *batch)
{
	const int elements = 34;
	int i;

	OUT_BATCH(GEN4_3DSTATE_VERTEX_ELEMENTS |
		(((2 * elements) + 1) - 2) /* DWORD count - 2 */);

	/* Element 0 */
	OUT_BATCH(GEN6_VE0_VALID);
	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);
	/* Elements 1 -> 33 */
	for (i = 1; i < elements; i++) {
		OUT_BATCH(0);
		OUT_BATCH(0);
	}
}

static void gen8_emit_cc_state_pointers(struct intel_batchbuffer *batch)
{
	union {
		float fval;
		uint32_t uval;
	} u;

	unsigned offset;

	u.fval = 1.0f;

	offset = intel_batch_state_offset(batch, 64);
	OUT_STATE(0);
	OUT_STATE(0);      /* Alpha reference value */
	OUT_STATE(u.uval); /* Blend constant color RED */
	OUT_STATE(u.uval); /* Blend constant color BLUE */
	OUT_STATE(u.uval); /* Blend constant color GREEN */
	OUT_STATE(u.uval); /* Blend constant color ALPHA */

	OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS);
	OUT_BATCH_STATE_OFFSET(offset | 1);
}

static void gen8_emit_blend_state_pointers(struct intel_batchbuffer *batch)
{
	unsigned offset;
	int i;

	offset = intel_batch_state_offset(batch, 64);

	for (i = 0; i < 17; i++)
		OUT_STATE(0);

	OUT_BATCH(GEN7_3DSTATE_BLEND_STATE_POINTERS | (2 - 2));
	OUT_BATCH_STATE_OFFSET(offset | 1);
}

static void gen8_emit_ps_extra(struct intel_batchbuffer *batch)
{
        OUT_BATCH(GEN8_3DSTATE_PS_EXTRA | (2 - 2));
        OUT_BATCH(GEN8_PSX_PIXEL_SHADER_VALID |
		  GEN8_PSX_ATTRIBUTE_ENABLE);

}

static void gen8_emit_ps_blend(struct intel_batchbuffer *batch)
{
        OUT_BATCH(GEN8_3DSTATE_PS_BLEND | (2 - 2));
        OUT_BATCH(GEN8_PS_BLEND_HAS_WRITEABLE_RT);
}

static void gen8_emit_viewport_state_pointers_cc(struct intel_batchbuffer *batch)
{
	unsigned offset;

	offset = intel_batch_state_offset(batch, 32);

	OUT_STATE((uint32_t)0.0f); /* Minimum depth */
	OUT_STATE((uint32_t)0.0f); /* Maximum depth */

	OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC | (2 - 2));
	OUT_BATCH_STATE_OFFSET(offset);
}

static void gen8_emit_viewport_state_pointers_sf_clip(struct intel_batchbuffer *batch)
{
	unsigned offset;
	int i;

	offset = intel_batch_state_offset(batch, 64);

	for (i = 0; i < 16; i++)
		OUT_STATE(0);

	OUT_BATCH(GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP | (2 - 2));
	OUT_BATCH_STATE_OFFSET(offset);
}

static void gen8_emit_primitive(struct intel_batchbuffer *batch)
{
	OUT_BATCH(GEN4_3DPRIMITIVE | (7 - 2));
	OUT_BATCH(4);   /* gen8+ ignore the topology type field */
	OUT_BATCH(1);   /* vertex count */
	OUT_BATCH(0);
	OUT_BATCH(1);   /* single instance */
	OUT_BATCH(0);   /* start instance location */
	OUT_BATCH(0);   /* index buffer offset, ignored */
}

static void gen9_emit_state_base_address(struct intel_batchbuffer *batch) {
	const unsigned offset = 0;
	OUT_BATCH(GEN4_STATE_BASE_ADDRESS |
		(19 - 2) /* DWORD count - 2 */);

	/* general state base address - requires BB address
	 * added to state offset to be stored in this location
	 */
	OUT_RELOC(batch, 0, 0, offset | BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);

	/* stateless data port */
	OUT_BATCH(0);

	/* surface state base address - requires BB address
	 * added to state offset to be stored in this location
	 */
	OUT_RELOC(batch, 0, 0, offset | BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);

	/* dynamic state base address - requires BB address
	 * added to state offset to be stored in this location
	 */
	OUT_RELOC(batch, 0, 0, offset | BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);

	/* indirect state base address */
	OUT_BATCH(BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);

	/* instruction state base address - requires BB address
	 * added to state offset to be stored in this location
	 */
	OUT_RELOC(batch, 0, 0, offset | BASE_ADDRESS_MODIFY);
	OUT_BATCH(0);

	/* general state buffer size */
	OUT_BATCH(GEN8_STATE_SIZE_PAGES(1) | BUFFER_SIZE_MODIFY);
	/* dynamic state buffer size */
	OUT_BATCH(GEN8_STATE_SIZE_PAGES(1) | BUFFER_SIZE_MODIFY);
	/* indirect object buffer size */
	OUT_BATCH(0x0 | BUFFER_SIZE_MODIFY);
	/* intruction buffer size */
	OUT_BATCH(GEN8_STATE_SIZE_PAGES(1) | BUFFER_SIZE_MODIFY);

	/* bindless surface state base address */
	OUT_BATCH(0);
	OUT_BATCH(0);
	/* bindless surface state size */
	OUT_BATCH(0);
}

/*
 * Generate the batch buffer commands needed to initialize the 3D engine
 * to its "golden state".
 */
void gen9_setup_null_render_state(struct intel_batchbuffer *batch)
{
	int i;

#define GEN8_PIPE_CONTROL_GLOBAL_GTT   (1 << 24)
	/* PIPE_CONTROL */
	OUT_BATCH(GEN6_PIPE_CONTROL |
	         (6 - 2));	/* DWORD count - 2 */
	OUT_BATCH(GEN8_PIPE_CONTROL_GLOBAL_GTT);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);

	/* PIPELINE_SELECT */
	OUT_BATCH(GEN9_PIPELINE_SELECT | PIPELINE_SELECT_3D);

	gen8_emit_wm(batch);
	gen8_emit_ps(batch);
	gen8_emit_sf(batch);

	OUT_CMD(GEN7_3DSTATE_SBE, 6); /* Check w/ Gen8 code */
	OUT_CMD(GEN8_3DSTATE_SBE_SWIZ, 11);

	gen8_emit_vs(batch);
	gen8_emit_hs(batch);

	OUT_CMD(GEN6_3DSTATE_GS, 10);
	OUT_CMD(GEN7_3DSTATE_STREAMOUT, 5);
	OUT_CMD(GEN7_3DSTATE_DS, 11); /* Check w/ Gen8 code */
	OUT_CMD(GEN6_3DSTATE_CLIP, 4);
	gen8_emit_raster(batch);
	OUT_CMD(GEN7_3DSTATE_TE, 4);
	OUT_CMD(GEN8_3DSTATE_VF, 2);
	OUT_CMD(GEN8_3DSTATE_WM_HZ_OP, 5);

	/* URB States */
	gen8_emit_urb(batch);

	OUT_CMD(GEN8_3DSTATE_BIND_TABLE_POOL_ALLOC, 4);
	OUT_CMD(GEN8_3DSTATE_GATHER_POOL_ALLOC, 4);
	OUT_CMD(GEN8_3DSTATE_DX9_CONSTANT_BUFFER_POOL_ALLOC, 4);

	/* Push Constants */
	OUT_CMD(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS, 2);
	OUT_CMD(GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_HS, 2);
	OUT_CMD(GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_DS, 2);
	OUT_CMD(GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_GS, 2);
	OUT_CMD(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS, 2);

	/* Constants */
	OUT_CMD(GEN6_3DSTATE_CONSTANT_VS, 11);
	OUT_CMD(GEN7_3DSTATE_CONSTANT_HS, 11);
	OUT_CMD(GEN7_3DSTATE_CONSTANT_DS, 11);
	OUT_CMD(GEN6_3DSTATE_CONSTANT_GS, 11);
	OUT_CMD(GEN6_3DSTATE_CONSTANT_PS, 11);

	OUT_CMD(GEN8_3DSTATE_VF_INSTANCING, 3);
	OUT_CMD(GEN8_3DSTATE_VF_SGVS, 2);
	gen8_emit_vf_topology(batch);

	/* Streamer out declaration list */
	gen8_emit_so_decl_list(batch);

	/* Streamer out buffers */
	for (i = 0; i < 4; i++) {
		gen8_emit_so_buffer(batch, i);
	}

	/* State base addresses */
	gen9_emit_state_base_address(batch);

	OUT_CMD(GEN4_STATE_SIP, 3);
	OUT_CMD(GEN4_3DSTATE_DRAWING_RECTANGLE, 4);
	OUT_CMD(GEN7_3DSTATE_DEPTH_BUFFER, 8);

	/* Chroma key */
	for (i = 0; i < 4; i++) {
		gen8_emit_chroma_key(batch, i);
	}

	OUT_CMD(GEN6_3DSTATE_LINE_STIPPLE, 3);
	OUT_CMD(GEN6_3DSTATE_AA_LINE_PARAMS, 3);
	OUT_CMD(GEN8_3DSTATE_STENCIL_BUFFER, 5);
	OUT_CMD(GEN8_3DSTATE_HIER_DEPTH_BUFFER, 5);
	OUT_CMD(GEN7_3DSTATE_CLEAR_PARAMS, 3);
	OUT_CMD(GEN6_3DSTATE_MONOFILTER_SIZE, 2);
	OUT_CMD(GEN8_3DSTATE_MULTISAMPLE, 2);
	OUT_CMD(GEN6_3DSTATE_POLY_STIPPLE_OFFSET, 2);
	OUT_CMD(GEN6_3DSTATE_POLY_STIPPLE_PATTERN, 1 + 32);
	OUT_CMD(GEN8_3DSTATE_SAMPLER_PALETTE_LOAD0, 1 + 16);
	OUT_CMD(GEN8_3DSTATE_SAMPLER_PALETTE_LOAD1, 1 + 16);
	OUT_CMD(GEN6_3DSTATE_INDEX_BUFFER, 5);

	/* Vertex buffers */
	gen8_emit_vertex_buffers(batch);
	gen8_emit_vertex_elements(batch);

	OUT_BATCH(GEN9_3DSTATE_COMPONENT_PACKING | 3);
	OUT_BATCH(0xf);
	OUT_BATCH(0);
	OUT_BATCH(0);
	OUT_BATCH(0);

	OUT_BATCH(GEN6_3DSTATE_VF_STATISTICS | 1 /* Enable */);

	gen8_emit_cc_state_pointers(batch);
	gen8_emit_blend_state_pointers(batch);
	gen8_emit_ps_extra(batch);
	gen8_emit_ps_blend(batch);

	/* 3D state sampler state pointers */
	OUT_CMD(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS, 2);
	OUT_CMD(GEN8_3DSTATE_SAMPLER_STATE_POINTERS_HS, 2);
	OUT_CMD(GEN8_3DSTATE_SAMPLER_STATE_POINTERS_DS, 2);
	OUT_CMD(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS, 2);
	OUT_CMD(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS, 2);

	OUT_CMD(GEN8_3DSTATE_SCISSOR_STATE_POINTERS, 2);

	gen8_emit_viewport_state_pointers_cc(batch);
	gen8_emit_viewport_state_pointers_sf_clip(batch);

	/* 3D state binding table pointers */
	OUT_CMD(GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS, 2);
	OUT_CMD(GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS, 2);
	OUT_CMD(GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS, 2);
	OUT_CMD(GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS, 2);
	OUT_CMD(GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS, 2);

	/* Launch 3D operation */
	gen8_emit_primitive(batch);

	OUT_BATCH(MI_BATCH_BUFFER_END);
}