1092
1093
state->last_primitive = sna->kgem.nbatch;
1095
static void gen7_vertex_flush(struct sna *sna)
1097
assert(sna->render_state.gen7.vertex_offset);
1099
DBG(("%s[%x] = %d\n", __FUNCTION__,
1100
4*sna->render_state.gen7.vertex_offset,
1101
sna->render.vertex_index - sna->render.vertex_start));
1102
sna->kgem.batch[sna->render_state.gen7.vertex_offset] =
1103
sna->render.vertex_index - sna->render.vertex_start;
1104
sna->render_state.gen7.vertex_offset = 0;
1107
static int gen7_vertex_finish(struct sna *sna)
1112
assert(sna->render.vertex_used);
1113
assert(sna->render.nvertex_reloc);
1115
/* Note: we only need dword alignment (currently) */
1117
bo = sna->render.vbo;
1119
if (sna->render_state.gen7.vertex_offset)
1120
gen7_vertex_flush(sna);
1122
for (i = 0; i < sna->render.nvertex_reloc; i++) {
1123
DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
1124
i, sna->render.vertex_reloc[i]));
1126
sna->kgem.batch[sna->render.vertex_reloc[i]] =
1127
kgem_add_reloc(&sna->kgem,
1128
sna->render.vertex_reloc[i], bo,
1129
I915_GEM_DOMAIN_VERTEX << 16,
1133
sna->render.nvertex_reloc = 0;
1134
sna->render.vertex_used = 0;
1135
sna->render.vertex_index = 0;
1136
sna->render.vbo = NULL;
1137
sna->render_state.gen7.vb_id = 0;
1139
kgem_bo_destroy(&sna->kgem, bo);
1142
sna->render.vertices = NULL;
1143
sna->render.vbo = kgem_create_linear(&sna->kgem,
1144
256*1024, CREATE_GTT_MAP);
1145
if (sna->render.vbo)
1146
sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
1147
if (sna->render.vertices == NULL) {
1148
if (sna->render.vbo)
1149
kgem_bo_destroy(&sna->kgem, sna->render.vbo);
1150
sna->render.vbo = NULL;
1154
kgem_bo_sync__cpu(&sna->kgem, sna->render.vbo);
1155
if (sna->render.vertex_used) {
1156
memcpy(sna->render.vertices,
1157
sna->render.vertex_data,
1158
sizeof(float)*sna->render.vertex_used);
1160
sna->render.vertex_size = 64 * 1024 - 1;
1161
return sna->render.vertex_size - sna->render.vertex_used;
1164
static void gen7_vertex_close(struct sna *sna)
1166
struct kgem_bo *bo, *free_bo = NULL;
1167
unsigned int i, delta = 0;
1169
assert(sna->render_state.gen7.vertex_offset == 0);
1171
if (!sna->render_state.gen7.vb_id)
1174
DBG(("%s: used=%d, vbo active? %d\n",
1175
__FUNCTION__, sna->render.vertex_used, sna->render.vbo ? sna->render.vbo->handle : 0));
1177
bo = sna->render.vbo;
1179
if (sna->render.vertex_size - sna->render.vertex_used < 64) {
1180
DBG(("%s: discarding vbo (full), handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
1181
sna->render.vbo = NULL;
1182
sna->render.vertices = sna->render.vertex_data;
1183
sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
1187
if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
1188
DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
1189
sna->render.vertex_used, sna->kgem.nbatch));
1190
memcpy(sna->kgem.batch + sna->kgem.nbatch,
1191
sna->render.vertex_data,
1192
sna->render.vertex_used * 4);
1193
delta = sna->kgem.nbatch * 4;
1195
sna->kgem.nbatch += sna->render.vertex_used;
1197
bo = kgem_create_linear(&sna->kgem,
1198
4*sna->render.vertex_used, 0);
1199
if (bo && !kgem_bo_write(&sna->kgem, bo,
1200
sna->render.vertex_data,
1201
4*sna->render.vertex_used)) {
1202
kgem_bo_destroy(&sna->kgem, bo);
1205
DBG(("%s: new vbo: %d\n", __FUNCTION__,
1206
sna->render.vertex_used));
1211
assert(sna->render.nvertex_reloc);
1212
for (i = 0; i < sna->render.nvertex_reloc; i++) {
1213
DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
1214
i, sna->render.vertex_reloc[i]));
1216
sna->kgem.batch[sna->render.vertex_reloc[i]] =
1217
kgem_add_reloc(&sna->kgem,
1218
sna->render.vertex_reloc[i], bo,
1219
I915_GEM_DOMAIN_VERTEX << 16,
1222
sna->render.nvertex_reloc = 0;
1224
if (sna->render.vbo == NULL) {
1225
sna->render.vertex_used = 0;
1226
sna->render.vertex_index = 0;
1227
assert(sna->render.vertices == sna->render.vertex_data);
1228
assert(sna->render.vertex_size == ARRAY_SIZE(sna->render.vertex_data));
1232
kgem_bo_destroy(&sna->kgem, free_bo);
1235
1096
static void null_create(struct sna_static_stream *stream)
1237
1098
/* A bunch of zeros useful for legacy border color and depth-stencil */
1383
1244
return offset * sizeof(uint32_t);
1386
fastcall static void
1387
gen7_emit_composite_primitive_solid(struct sna *sna,
1388
const struct sna_composite_op *op,
1389
const struct sna_composite_rectangles *r)
1393
struct sna_coordinate p;
1397
v = sna->render.vertices + sna->render.vertex_used;
1398
sna->render.vertex_used += 9;
1399
assert(sna->render.vertex_used <= sna->render.vertex_size);
1400
assert(!too_large(op->dst.x + r->dst.x + r->width,
1401
op->dst.y + r->dst.y + r->height));
1403
dst.p.x = r->dst.x + r->width;
1404
dst.p.y = r->dst.y + r->height;
1411
v[5] = v[2] = v[1] = 1.;
1412
v[8] = v[7] = v[4] = 0.;
1415
fastcall static void
1416
gen7_emit_composite_primitive_identity_source(struct sna *sna,
1417
const struct sna_composite_op *op,
1418
const struct sna_composite_rectangles *r)
1421
struct sna_coordinate p;
1426
v = sna->render.vertices + sna->render.vertex_used;
1427
sna->render.vertex_used += 9;
1429
dst.p.x = r->dst.x + r->width;
1430
dst.p.y = r->dst.y + r->height;
1437
v[7] = v[4] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
1438
v[1] = v[4] + r->width * op->src.scale[0];
1440
v[8] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
1441
v[5] = v[2] = v[8] + r->height * op->src.scale[1];
1444
fastcall static void
1445
gen7_emit_composite_primitive_simple_source(struct sna *sna,
1446
const struct sna_composite_op *op,
1447
const struct sna_composite_rectangles *r)
1451
struct sna_coordinate p;
1455
float xx = op->src.transform->matrix[0][0];
1456
float x0 = op->src.transform->matrix[0][2];
1457
float yy = op->src.transform->matrix[1][1];
1458
float y0 = op->src.transform->matrix[1][2];
1459
float sx = op->src.scale[0];
1460
float sy = op->src.scale[1];
1461
int16_t tx = op->src.offset[0];
1462
int16_t ty = op->src.offset[1];
1464
v = sna->render.vertices + sna->render.vertex_used;
1465
sna->render.vertex_used += 3*3;
1467
dst.p.x = r->dst.x + r->width;
1468
dst.p.y = r->dst.y + r->height;
1470
v[1] = ((r->src.x + r->width + tx) * xx + x0) * sx;
1471
v[5] = v[2] = ((r->src.y + r->height + ty) * yy + y0) * sy;
1475
v[7] = v[4] = ((r->src.x + tx) * xx + x0) * sx;
1479
v[8] = ((r->src.y + ty) * yy + y0) * sy;
1482
fastcall static void
1483
gen7_emit_composite_primitive_affine_source(struct sna *sna,
1484
const struct sna_composite_op *op,
1485
const struct sna_composite_rectangles *r)
1488
struct sna_coordinate p;
1493
v = sna->render.vertices + sna->render.vertex_used;
1494
sna->render.vertex_used += 9;
1496
dst.p.x = r->dst.x + r->width;
1497
dst.p.y = r->dst.y + r->height;
1499
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
1500
op->src.offset[1] + r->src.y + r->height,
1503
v[1] *= op->src.scale[0];
1504
v[2] *= op->src.scale[1];
1508
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
1509
op->src.offset[1] + r->src.y + r->height,
1512
v[4] *= op->src.scale[0];
1513
v[5] *= op->src.scale[1];
1517
_sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
1518
op->src.offset[1] + r->src.y,
1521
v[7] *= op->src.scale[0];
1522
v[8] *= op->src.scale[1];
1525
fastcall static void
1526
gen7_emit_composite_primitive_identity_mask(struct sna *sna,
1527
const struct sna_composite_op *op,
1528
const struct sna_composite_rectangles *r)
1531
struct sna_coordinate p;
1538
msk_x = r->mask.x + op->mask.offset[0];
1539
msk_y = r->mask.y + op->mask.offset[1];
1543
v = sna->render.vertices + sna->render.vertex_used;
1544
sna->render.vertex_used += 15;
1546
dst.p.x = r->dst.x + r->width;
1547
dst.p.y = r->dst.y + r->height;
1549
v[3] = (msk_x + w) * op->mask.scale[0];
1550
v[9] = v[4] = (msk_y + h) * op->mask.scale[1];
1554
v[13] = v[8] = msk_x * op->mask.scale[0];
1558
v[14] = msk_y * op->mask.scale[1];
1560
v[7] = v[2] = v[1] = 1;
1561
v[12] = v[11] = v[6] = 0;
1564
fastcall static void
1565
gen7_emit_composite_primitive_identity_source_mask(struct sna *sna,
1566
const struct sna_composite_op *op,
1567
const struct sna_composite_rectangles *r)
1570
struct sna_coordinate p;
1578
src_x = r->src.x + op->src.offset[0];
1579
src_y = r->src.y + op->src.offset[1];
1580
msk_x = r->mask.x + op->mask.offset[0];
1581
msk_y = r->mask.y + op->mask.offset[1];
1585
v = sna->render.vertices + sna->render.vertex_used;
1586
sna->render.vertex_used += 15;
1588
dst.p.x = r->dst.x + r->width;
1589
dst.p.y = r->dst.y + r->height;
1591
v[1] = (src_x + w) * op->src.scale[0];
1592
v[2] = (src_y + h) * op->src.scale[1];
1593
v[3] = (msk_x + w) * op->mask.scale[0];
1594
v[4] = (msk_y + h) * op->mask.scale[1];
1598
v[6] = src_x * op->src.scale[0];
1600
v[8] = msk_x * op->mask.scale[0];
1606
v[12] = src_y * op->src.scale[1];
1608
v[14] = msk_y * op->mask.scale[1];
1612
gen7_emit_composite_texcoord(struct sna *sna,
1613
const struct sna_composite_channel *channel,
1614
int16_t x, int16_t y)
1616
x += channel->offset[0];
1617
y += channel->offset[1];
1619
if (channel->is_affine) {
1622
sna_get_transformed_coordinates(x, y,
1625
OUT_VERTEX_F(s * channel->scale[0]);
1626
OUT_VERTEX_F(t * channel->scale[1]);
1630
sna_get_transformed_coordinates_3d(x, y,
1633
OUT_VERTEX_F(s * channel->scale[0]);
1634
OUT_VERTEX_F(t * channel->scale[1]);
1640
gen7_emit_composite_vertex(struct sna *sna,
1641
const struct sna_composite_op *op,
1642
int16_t srcX, int16_t srcY,
1643
int16_t mskX, int16_t mskY,
1644
int16_t dstX, int16_t dstY)
1646
OUT_VERTEX(dstX, dstY);
1647
gen7_emit_composite_texcoord(sna, &op->src, srcX, srcY);
1648
gen7_emit_composite_texcoord(sna, &op->mask, mskX, mskY);
1651
fastcall static void
1652
gen7_emit_composite_primitive(struct sna *sna,
1653
const struct sna_composite_op *op,
1654
const struct sna_composite_rectangles *r)
1656
gen7_emit_composite_vertex(sna, op,
1657
r->src.x + r->width, r->src.y + r->height,
1658
r->mask.x + r->width, r->mask.y + r->height,
1659
r->dst.x + r->width, r->dst.y + r->height);
1660
gen7_emit_composite_vertex(sna, op,
1661
r->src.x, r->src.y + r->height,
1662
r->mask.x, r->mask.y + r->height,
1663
r->dst.x, r->dst.y + r->height);
1664
gen7_emit_composite_vertex(sna, op,
1666
r->mask.x, r->mask.y,
1667
r->dst.x, r->dst.y);
1670
1247
static void gen7_emit_vertex_buffer(struct sna *sna,
1671
1248
const struct sna_composite_op *op)
2990
2534
#if !NO_COMPOSITE_SPANS
2992
gen7_emit_composite_texcoord_affine(struct sna *sna,
2993
const struct sna_composite_channel *channel,
2994
int16_t x, int16_t y)
2998
sna_get_transformed_coordinates(x + channel->offset[0],
2999
y + channel->offset[1],
3002
OUT_VERTEX_F(t[0] * channel->scale[0]);
3003
OUT_VERTEX_F(t[1] * channel->scale[1]);
3007
gen7_emit_composite_spans_vertex(struct sna *sna,
3008
const struct sna_composite_spans_op *op,
3009
int16_t x, int16_t y)
3012
gen7_emit_composite_texcoord(sna, &op->base.src, x, y);
3015
fastcall static void
3016
gen7_emit_composite_spans_primitive(struct sna *sna,
3017
const struct sna_composite_spans_op *op,
3021
gen7_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
3022
OUT_VERTEX_F(opacity);
3024
gen7_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
3025
OUT_VERTEX_F(opacity);
3027
gen7_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
3028
OUT_VERTEX_F(opacity);
3031
fastcall static void
3032
gen7_emit_composite_spans_solid(struct sna *sna,
3033
const struct sna_composite_spans_op *op,
3037
OUT_VERTEX(box->x2, box->y2);
3038
OUT_VERTEX_F(1); OUT_VERTEX_F(1);
3039
OUT_VERTEX_F(opacity);
3041
OUT_VERTEX(box->x1, box->y2);
3042
OUT_VERTEX_F(0); OUT_VERTEX_F(1);
3043
OUT_VERTEX_F(opacity);
3045
OUT_VERTEX(box->x1, box->y1);
3046
OUT_VERTEX_F(0); OUT_VERTEX_F(0);
3047
OUT_VERTEX_F(opacity);
3050
fastcall static void
3051
gen7_emit_composite_spans_identity(struct sna *sna,
3052
const struct sna_composite_spans_op *op,
3058
struct sna_coordinate p;
3062
float sx = op->base.src.scale[0];
3063
float sy = op->base.src.scale[1];
3064
int16_t tx = op->base.src.offset[0];
3065
int16_t ty = op->base.src.offset[1];
3067
v = sna->render.vertices + sna->render.vertex_used;
3068
sna->render.vertex_used += 3*4;
3069
assert(sna->render.vertex_used <= sna->render.vertex_size);
3074
v[1] = (box->x2 + tx) * sx;
3075
v[6] = v[2] = (box->y2 + ty) * sy;
3079
v[9] = v[5] = (box->x1 + tx) * sx;
3083
v[10] = (box->y1 + ty) * sy;
3085
v[11] = v[7] = v[3] = opacity;
3088
fastcall static void
3089
gen7_emit_composite_spans_simple(struct sna *sna,
3090
const struct sna_composite_spans_op *op,
3096
struct sna_coordinate p;
3100
float xx = op->base.src.transform->matrix[0][0];
3101
float x0 = op->base.src.transform->matrix[0][2];
3102
float yy = op->base.src.transform->matrix[1][1];
3103
float y0 = op->base.src.transform->matrix[1][2];
3104
float sx = op->base.src.scale[0];
3105
float sy = op->base.src.scale[1];
3106
int16_t tx = op->base.src.offset[0];
3107
int16_t ty = op->base.src.offset[1];
3109
v = sna->render.vertices + sna->render.vertex_used;
3110
sna->render.vertex_used += 3*4;
3111
assert(sna->render.vertex_used <= sna->render.vertex_size);
3116
v[1] = ((box->x2 + tx) * xx + x0) * sx;
3117
v[6] = v[2] = ((box->y2 + ty) * yy + y0) * sy;
3121
v[9] = v[5] = ((box->x1 + tx) * xx + x0) * sx;
3125
v[10] = ((box->y1 + ty) * yy + y0) * sy;
3127
v[11] = v[7] = v[3] = opacity;
3130
fastcall static void
3131
gen7_emit_composite_spans_affine(struct sna *sna,
3132
const struct sna_composite_spans_op *op,
3136
OUT_VERTEX(box->x2, box->y2);
3137
gen7_emit_composite_texcoord_affine(sna, &op->base.src,
3139
OUT_VERTEX_F(opacity);
3141
OUT_VERTEX(box->x1, box->y2);
3142
gen7_emit_composite_texcoord_affine(sna, &op->base.src,
3144
OUT_VERTEX_F(opacity);
3146
OUT_VERTEX(box->x1, box->y1);
3147
gen7_emit_composite_texcoord_affine(sna, &op->base.src,
3149
OUT_VERTEX_F(opacity);
3152
2535
fastcall static void
3153
2536
gen7_render_composite_spans_box(struct sna *sna,
3154
2537
const struct sna_composite_spans_op *op,