947
948
state->last_primitive = sna->kgem.nbatch;
950
static void gen6_vertex_flush(struct sna *sna)
952
assert(sna->render_state.gen6.vertex_offset);
954
DBG(("%s[%x] = %d\n", __FUNCTION__,
955
4*sna->render_state.gen6.vertex_offset,
956
sna->render.vertex_index - sna->render.vertex_start));
957
sna->kgem.batch[sna->render_state.gen6.vertex_offset] =
958
sna->render.vertex_index - sna->render.vertex_start;
959
sna->render_state.gen6.vertex_offset = 0;
962
static int gen6_vertex_finish(struct sna *sna)
967
DBG(("%s: used=%d / %d\n", __FUNCTION__,
968
sna->render.vertex_used, sna->render.vertex_size));
969
assert(sna->render.vertex_used);
970
assert(sna->render.nvertex_reloc);
972
/* Note: we only need dword alignment (currently) */
974
bo = sna->render.vbo;
976
if (sna->render_state.gen6.vertex_offset)
977
gen6_vertex_flush(sna);
979
for (i = 0; i < sna->render.nvertex_reloc; i++) {
980
DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
981
i, sna->render.vertex_reloc[i]));
983
sna->kgem.batch[sna->render.vertex_reloc[i]] =
984
kgem_add_reloc(&sna->kgem,
985
sna->render.vertex_reloc[i], bo,
986
I915_GEM_DOMAIN_VERTEX << 16,
990
sna->render.nvertex_reloc = 0;
991
sna->render.vertex_used = 0;
992
sna->render.vertex_index = 0;
993
sna->render.vbo = NULL;
994
sna->render_state.gen6.vb_id = 0;
996
kgem_bo_destroy(&sna->kgem, bo);
999
sna->render.vertices = NULL;
1000
sna->render.vbo = kgem_create_linear(&sna->kgem,
1001
256*1024, CREATE_GTT_MAP);
1002
if (sna->render.vbo)
1003
sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
1004
if (sna->render.vertices == NULL) {
1005
if (sna->render.vbo)
1006
kgem_bo_destroy(&sna->kgem, sna->render.vbo);
1007
sna->render.vbo = NULL;
1011
DBG(("%s: create vbo handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
1013
kgem_bo_sync__cpu(&sna->kgem, sna->render.vbo);
1014
if (sna->render.vertex_used) {
1015
DBG(("%s: copying initial buffer x %d to handle=%d\n",
1017
sna->render.vertex_used,
1018
sna->render.vbo->handle));
1019
memcpy(sna->render.vertices,
1020
sna->render.vertex_data,
1021
sizeof(float)*sna->render.vertex_used);
1023
sna->render.vertex_size = 64 * 1024 - 1;
1024
return sna->render.vertex_size - sna->render.vertex_used;
1027
static void gen6_vertex_close(struct sna *sna)
1029
struct kgem_bo *bo, *free_bo = NULL;
1030
unsigned int i, delta = 0;
1032
assert(sna->render_state.gen6.vertex_offset == 0);
1034
if (!sna->render_state.gen6.vb_id)
1037
DBG(("%s: used=%d, vbo active? %d\n",
1038
__FUNCTION__, sna->render.vertex_used, sna->render.vbo ? sna->render.vbo->handle : 0));
1040
bo = sna->render.vbo;
1042
if (sna->render.vertex_size - sna->render.vertex_used < 64) {
1043
DBG(("%s: discarding vbo (full), handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
1044
sna->render.vbo = NULL;
1045
sna->render.vertices = sna->render.vertex_data;
1046
sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
1050
if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
1051
DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
1052
sna->render.vertex_used, sna->kgem.nbatch));
1053
memcpy(sna->kgem.batch + sna->kgem.nbatch,
1054
sna->render.vertex_data,
1055
sna->render.vertex_used * 4);
1056
delta = sna->kgem.nbatch * 4;
1058
sna->kgem.nbatch += sna->render.vertex_used;
1060
bo = kgem_create_linear(&sna->kgem,
1061
4*sna->render.vertex_used, 0);
1062
if (bo && !kgem_bo_write(&sna->kgem, bo,
1063
sna->render.vertex_data,
1064
4*sna->render.vertex_used)) {
1065
kgem_bo_destroy(&sna->kgem, bo);
1068
DBG(("%s: new vbo: %d\n", __FUNCTION__,
1069
sna->render.vertex_used));
1074
assert(sna->render.nvertex_reloc);
1075
for (i = 0; i < sna->render.nvertex_reloc; i++) {
1076
DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
1077
i, sna->render.vertex_reloc[i]));
1079
sna->kgem.batch[sna->render.vertex_reloc[i]] =
1080
kgem_add_reloc(&sna->kgem,
1081
sna->render.vertex_reloc[i], bo,
1082
I915_GEM_DOMAIN_VERTEX << 16,
1085
sna->render.nvertex_reloc = 0;
1087
if (sna->render.vbo == NULL) {
1088
sna->render.vertex_used = 0;
1089
sna->render.vertex_index = 0;
1090
assert(sna->render.vertices == sna->render.vertex_data);
1091
assert(sna->render.vertex_size == ARRAY_SIZE(sna->render.vertex_data));
1095
kgem_bo_destroy(&sna->kgem, free_bo);
1098
951
typedef struct gen6_surface_state_padded {
1099
952
struct gen6_surface_state state;
1100
953
char pad[32 - sizeof(struct gen6_surface_state)];
1258
1111
return offset * sizeof(uint32_t);
1261
fastcall static void
1262
gen6_emit_composite_primitive_solid(struct sna *sna,
1263
const struct sna_composite_op *op,
1264
const struct sna_composite_rectangles *r)
1268
struct sna_coordinate p;
1272
DBG(("%s: [%d+9] = (%d, %d)x(%d, %d)\n", __FUNCTION__,
1273
sna->render.vertex_used, r->dst.x, r->dst.y, r->width, r->height));
1275
v = sna->render.vertices + sna->render.vertex_used;
1276
sna->render.vertex_used += 9;
1277
assert(sna->render.vertex_used <= sna->render.vertex_size);
1278
assert(!too_large(op->dst.x + r->dst.x + r->width,
1279
op->dst.y + r->dst.y + r->height));
1281
dst.p.x = r->dst.x + r->width;
1282
dst.p.y = r->dst.y + r->height;
1289
v[5] = v[2] = v[1] = 1.;
1290
v[8] = v[7] = v[4] = 0.;
1293
fastcall static void
1294
gen6_emit_composite_primitive_identity_source(struct sna *sna,
1295
const struct sna_composite_op *op,
1296
const struct sna_composite_rectangles *r)
1299
struct sna_coordinate p;
1304
v = sna->render.vertices + sna->render.vertex_used;
1305
sna->render.vertex_used += 9;
1307
dst.p.x = r->dst.x + r->width;
1308
dst.p.y = r->dst.y + r->height;
1315
v[7] = v[4] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
1316
v[1] = v[4] + r->width * op->src.scale[0];
1318
v[8] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
1319
v[5] = v[2] = v[8] + r->height * op->src.scale[1];
1322
fastcall static void
1323
gen6_emit_composite_primitive_simple_source(struct sna *sna,
1324
const struct sna_composite_op *op,
1325
const struct sna_composite_rectangles *r)
1329
struct sna_coordinate p;
1333
float xx = op->src.transform->matrix[0][0];
1334
float x0 = op->src.transform->matrix[0][2];
1335
float yy = op->src.transform->matrix[1][1];
1336
float y0 = op->src.transform->matrix[1][2];
1337
float sx = op->src.scale[0];
1338
float sy = op->src.scale[1];
1339
int16_t tx = op->src.offset[0];
1340
int16_t ty = op->src.offset[1];
1342
v = sna->render.vertices + sna->render.vertex_used;
1343
sna->render.vertex_used += 3*3;
1345
dst.p.x = r->dst.x + r->width;
1346
dst.p.y = r->dst.y + r->height;
1348
v[1] = ((r->src.x + r->width + tx) * xx + x0) * sx;
1349
v[5] = v[2] = ((r->src.y + r->height + ty) * yy + y0) * sy;
1353
v[7] = v[4] = ((r->src.x + tx) * xx + x0) * sx;
1357
v[8] = ((r->src.y + ty) * yy + y0) * sy;
1360
fastcall static void
1361
gen6_emit_composite_primitive_affine_source(struct sna *sna,
1362
const struct sna_composite_op *op,
1363
const struct sna_composite_rectangles *r)
1366
struct sna_coordinate p;
1371
v = sna->render.vertices + sna->render.vertex_used;
1372
sna->render.vertex_used += 9;
1374
dst.p.x = r->dst.x + r->width;
1375
dst.p.y = r->dst.y + r->height;
1377
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
1378
op->src.offset[1] + r->src.y + r->height,
1381
v[1] *= op->src.scale[0];
1382
v[2] *= op->src.scale[1];
1386
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
1387
op->src.offset[1] + r->src.y + r->height,
1390
v[4] *= op->src.scale[0];
1391
v[5] *= op->src.scale[1];
1395
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
1396
op->src.offset[1] + r->src.y,
1399
v[7] *= op->src.scale[0];
1400
v[8] *= op->src.scale[1];
1403
fastcall static void
1404
gen6_emit_composite_primitive_identity_mask(struct sna *sna,
1405
const struct sna_composite_op *op,
1406
const struct sna_composite_rectangles *r)
1409
struct sna_coordinate p;
1416
msk_x = r->mask.x + op->mask.offset[0];
1417
msk_y = r->mask.y + op->mask.offset[1];
1421
v = sna->render.vertices + sna->render.vertex_used;
1422
sna->render.vertex_used += 15;
1424
dst.p.x = r->dst.x + r->width;
1425
dst.p.y = r->dst.y + r->height;
1427
v[3] = (msk_x + w) * op->mask.scale[0];
1428
v[9] = v[4] = (msk_y + h) * op->mask.scale[1];
1432
v[13] = v[8] = msk_x * op->mask.scale[0];
1436
v[14] = msk_y * op->mask.scale[1];
1438
v[7] = v[2] = v[1] = 1;
1439
v[12] = v[11] = v[6] = 0;
1442
fastcall static void
1443
gen6_emit_composite_primitive_identity_source_mask(struct sna *sna,
1444
const struct sna_composite_op *op,
1445
const struct sna_composite_rectangles *r)
1448
struct sna_coordinate p;
1456
src_x = r->src.x + op->src.offset[0];
1457
src_y = r->src.y + op->src.offset[1];
1458
msk_x = r->mask.x + op->mask.offset[0];
1459
msk_y = r->mask.y + op->mask.offset[1];
1463
v = sna->render.vertices + sna->render.vertex_used;
1464
sna->render.vertex_used += 15;
1466
dst.p.x = r->dst.x + r->width;
1467
dst.p.y = r->dst.y + r->height;
1469
v[1] = (src_x + w) * op->src.scale[0];
1470
v[2] = (src_y + h) * op->src.scale[1];
1471
v[3] = (msk_x + w) * op->mask.scale[0];
1472
v[4] = (msk_y + h) * op->mask.scale[1];
1476
v[6] = src_x * op->src.scale[0];
1478
v[8] = msk_x * op->mask.scale[0];
1484
v[12] = src_y * op->src.scale[1];
1486
v[14] = msk_y * op->mask.scale[1];
1490
gen6_emit_composite_texcoord(struct sna *sna,
1491
const struct sna_composite_channel *channel,
1492
int16_t x, int16_t y)
1494
x += channel->offset[0];
1495
y += channel->offset[1];
1497
if (channel->is_affine) {
1500
sna_get_transformed_coordinates(x, y,
1503
OUT_VERTEX_F(s * channel->scale[0]);
1504
OUT_VERTEX_F(t * channel->scale[1]);
1508
sna_get_transformed_coordinates_3d(x, y,
1511
OUT_VERTEX_F(s * channel->scale[0]);
1512
OUT_VERTEX_F(t * channel->scale[1]);
1518
gen6_emit_composite_vertex(struct sna *sna,
1519
const struct sna_composite_op *op,
1520
int16_t srcX, int16_t srcY,
1521
int16_t mskX, int16_t mskY,
1522
int16_t dstX, int16_t dstY)
1524
OUT_VERTEX(dstX, dstY);
1525
gen6_emit_composite_texcoord(sna, &op->src, srcX, srcY);
1526
gen6_emit_composite_texcoord(sna, &op->mask, mskX, mskY);
1529
fastcall static void
1530
gen6_emit_composite_primitive(struct sna *sna,
1531
const struct sna_composite_op *op,
1532
const struct sna_composite_rectangles *r)
1534
gen6_emit_composite_vertex(sna, op,
1535
r->src.x + r->width, r->src.y + r->height,
1536
r->mask.x + r->width, r->mask.y + r->height,
1537
r->dst.x + r->width, r->dst.y + r->height);
1538
gen6_emit_composite_vertex(sna, op,
1539
r->src.x, r->src.y + r->height,
1540
r->mask.x, r->mask.y + r->height,
1541
r->dst.x, r->dst.y + r->height);
1542
gen6_emit_composite_vertex(sna, op,
1544
r->mask.x, r->mask.y,
1545
r->dst.x, r->dst.y);
1548
1114
static void gen6_emit_vertex_buffer(struct sna *sna,
1549
1115
const struct sna_composite_op *op)
2795
2353
tmp->is_affine &= tmp->mask.is_affine;
2797
if (tmp->src.transform == NULL && tmp->mask.transform == NULL) {
2798
if (tmp->src.is_solid)
2799
tmp->prim_emit = gen6_emit_composite_primitive_identity_mask;
2801
tmp->prim_emit = gen6_emit_composite_primitive_identity_source_mask;
2804
tmp->floats_per_vertex = 5 + 2 * !tmp->is_affine;
2806
if (tmp->src.is_solid) {
2807
DBG(("%s: choosing gen6_emit_composite_primitive_solid\n",
2809
tmp->prim_emit = gen6_emit_composite_primitive_solid;
2810
if (tmp->src.is_opaque && op == PictOpOver)
2811
tmp->op = PictOpSrc;
2812
} else if (tmp->src.transform == NULL) {
2813
DBG(("%s: choosing gen6_emit_composite_primitive_identity_source\n",
2815
tmp->prim_emit = gen6_emit_composite_primitive_identity_source;
2816
} else if (tmp->src.is_affine) {
2817
if (tmp->src.transform->matrix[0][1] == 0 &&
2818
tmp->src.transform->matrix[1][0] == 0) {
2819
tmp->src.scale[0] /= tmp->src.transform->matrix[2][2];
2820
tmp->src.scale[1] /= tmp->src.transform->matrix[2][2];
2821
DBG(("%s: choosing gen6_emit_composite_primitive_simple_source\n",
2823
tmp->prim_emit = gen6_emit_composite_primitive_simple_source;
2825
DBG(("%s: choosing gen6_emit_composite_primitive_affine_source\n",
2827
tmp->prim_emit = gen6_emit_composite_primitive_affine_source;
2831
tmp->floats_per_vertex = 3 + !tmp->is_affine;
2833
tmp->floats_per_rect = 3 * tmp->floats_per_vertex;
2355
gen4_choose_composite_emitter(tmp);
2835
2357
tmp->u.gen6.flags =
2836
2358
GEN6_SET_FLAGS(SAMPLER_OFFSET(tmp->src.filter,
2882
2404
#if !NO_COMPOSITE_SPANS
2884
gen6_emit_composite_texcoord_affine(struct sna *sna,
2885
const struct sna_composite_channel *channel,
2886
int16_t x, int16_t y)
2890
sna_get_transformed_coordinates(x + channel->offset[0],
2891
y + channel->offset[1],
2894
OUT_VERTEX_F(t[0] * channel->scale[0]);
2895
OUT_VERTEX_F(t[1] * channel->scale[1]);
2899
gen6_emit_composite_spans_vertex(struct sna *sna,
2900
const struct sna_composite_spans_op *op,
2901
int16_t x, int16_t y)
2904
gen6_emit_composite_texcoord(sna, &op->base.src, x, y);
2907
fastcall static void
2908
gen6_emit_composite_spans_primitive(struct sna *sna,
2909
const struct sna_composite_spans_op *op,
2913
gen6_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
2914
OUT_VERTEX_F(opacity);
2916
gen6_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
2917
OUT_VERTEX_F(opacity);
2919
gen6_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
2920
OUT_VERTEX_F(opacity);
2923
fastcall static void
2924
gen6_emit_composite_spans_solid(struct sna *sna,
2925
const struct sna_composite_spans_op *op,
2929
OUT_VERTEX(box->x2, box->y2);
2930
OUT_VERTEX_F(1); OUT_VERTEX_F(1);
2931
OUT_VERTEX_F(opacity);
2933
OUT_VERTEX(box->x1, box->y2);
2934
OUT_VERTEX_F(0); OUT_VERTEX_F(1);
2935
OUT_VERTEX_F(opacity);
2937
OUT_VERTEX(box->x1, box->y1);
2938
OUT_VERTEX_F(0); OUT_VERTEX_F(0);
2939
OUT_VERTEX_F(opacity);
2942
fastcall static void
2943
gen6_emit_composite_spans_identity(struct sna *sna,
2944
const struct sna_composite_spans_op *op,
2950
struct sna_coordinate p;
2954
float sx = op->base.src.scale[0];
2955
float sy = op->base.src.scale[1];
2956
int16_t tx = op->base.src.offset[0];
2957
int16_t ty = op->base.src.offset[1];
2959
v = sna->render.vertices + sna->render.vertex_used;
2960
sna->render.vertex_used += 3*4;
2961
assert(sna->render.vertex_used <= sna->render.vertex_size);
2966
v[1] = (box->x2 + tx) * sx;
2967
v[6] = v[2] = (box->y2 + ty) * sy;
2971
v[9] = v[5] = (box->x1 + tx) * sx;
2975
v[10] = (box->y1 + ty) * sy;
2977
v[11] = v[7] = v[3] = opacity;
2980
fastcall static void
2981
gen6_emit_composite_spans_simple(struct sna *sna,
2982
const struct sna_composite_spans_op *op,
2988
struct sna_coordinate p;
2992
float xx = op->base.src.transform->matrix[0][0];
2993
float x0 = op->base.src.transform->matrix[0][2];
2994
float yy = op->base.src.transform->matrix[1][1];
2995
float y0 = op->base.src.transform->matrix[1][2];
2996
float sx = op->base.src.scale[0];
2997
float sy = op->base.src.scale[1];
2998
int16_t tx = op->base.src.offset[0];
2999
int16_t ty = op->base.src.offset[1];
3001
v = sna->render.vertices + sna->render.vertex_used;
3002
sna->render.vertex_used += 3*4;
3003
assert(sna->render.vertex_used <= sna->render.vertex_size);
3008
v[1] = ((box->x2 + tx) * xx + x0) * sx;
3009
v[6] = v[2] = ((box->y2 + ty) * yy + y0) * sy;
3013
v[9] = v[5] = ((box->x1 + tx) * xx + x0) * sx;
3017
v[10] = ((box->y1 + ty) * yy + y0) * sy;
3019
v[11] = v[7] = v[3] = opacity;
3022
fastcall static void
3023
gen6_emit_composite_spans_affine(struct sna *sna,
3024
const struct sna_composite_spans_op *op,
3028
OUT_VERTEX(box->x2, box->y2);
3029
gen6_emit_composite_texcoord_affine(sna, &op->base.src,
3031
OUT_VERTEX_F(opacity);
3033
OUT_VERTEX(box->x1, box->y2);
3034
gen6_emit_composite_texcoord_affine(sna, &op->base.src,
3036
OUT_VERTEX_F(opacity);
3038
OUT_VERTEX(box->x1, box->y1);
3039
gen6_emit_composite_texcoord_affine(sna, &op->base.src,
3041
OUT_VERTEX_F(opacity);
3044
2405
fastcall static void
3045
2406
gen6_render_composite_spans_box(struct sna *sna,
3046
2407
const struct sna_composite_spans_op *op,