~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/util/u_gen_mipmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
   struct pipe_rasterizer_state rasterizer;
63
63
   struct pipe_sampler_state sampler;
64
64
   struct pipe_clip_state clip;
 
65
   struct pipe_vertex_element velem[2];
65
66
 
66
67
   void *vs;
67
68
   void *fs2d, *fsCube;
68
69
 
69
 
   struct pipe_buffer *vbuf;  /**< quad vertices */
 
70
   struct pipe_resource *vbuf;  /**< quad vertices */
70
71
   unsigned vbuf_slot;
71
72
 
72
73
   float vertices[4][2][4];   /**< vertex/texcoords for quad */
937
938
      *datatype = DTYPE_UBYTE;
938
939
      *comps = 4;
939
940
      return;
 
941
   case PIPE_FORMAT_B5G5R5X1_UNORM:
940
942
   case PIPE_FORMAT_B5G5R5A1_UNORM:
941
943
      *datatype = DTYPE_USHORT_1_5_5_5_REV;
942
944
      *comps = 4;
1114
1116
 
1115
1117
static void
1116
1118
make_1d_mipmap(struct gen_mipmap_state *ctx,
1117
 
               struct pipe_texture *pt,
 
1119
               struct pipe_resource *pt,
1118
1120
               uint face, uint baseLevel, uint lastLevel)
1119
1121
{
1120
1122
   struct pipe_context *pipe = ctx->pipe;
1121
 
   struct pipe_screen *screen = pipe->screen;
1122
1123
   const uint zslice = 0;
1123
1124
   uint dstLevel;
1124
1125
 
1127
1128
      struct pipe_transfer *srcTrans, *dstTrans;
1128
1129
      void *srcMap, *dstMap;
1129
1130
      
1130
 
      srcTrans = screen->get_tex_transfer(screen, pt, face, srcLevel, zslice,
 
1131
      srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
1131
1132
                                          PIPE_TRANSFER_READ, 0, 0,
1132
1133
                                          u_minify(pt->width0, srcLevel),
1133
1134
                                          u_minify(pt->height0, srcLevel));
1134
 
      dstTrans = screen->get_tex_transfer(screen, pt, face, dstLevel, zslice,
 
1135
      dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
1135
1136
                                          PIPE_TRANSFER_WRITE, 0, 0,
1136
1137
                                          u_minify(pt->width0, dstLevel),
1137
1138
                                          u_minify(pt->height0, dstLevel));
1138
1139
 
1139
 
      srcMap = (ubyte *) screen->transfer_map(screen, srcTrans);
1140
 
      dstMap = (ubyte *) screen->transfer_map(screen, dstTrans);
 
1140
      srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
 
1141
      dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
1141
1142
 
1142
1143
      reduce_1d(pt->format,
1143
 
                srcTrans->width, srcMap,
1144
 
                dstTrans->width, dstMap);
1145
 
 
1146
 
      screen->transfer_unmap(screen, srcTrans);
1147
 
      screen->transfer_unmap(screen, dstTrans);
1148
 
 
1149
 
      screen->tex_transfer_destroy(srcTrans);
1150
 
      screen->tex_transfer_destroy(dstTrans);
 
1144
                srcTrans->box.width, srcMap,
 
1145
                dstTrans->box.width, dstMap);
 
1146
 
 
1147
      pipe->transfer_unmap(pipe, srcTrans);
 
1148
      pipe->transfer_unmap(pipe, dstTrans);
 
1149
 
 
1150
      pipe->transfer_destroy(pipe, srcTrans);
 
1151
      pipe->transfer_destroy(pipe, dstTrans);
1151
1152
   }
1152
1153
}
1153
1154
 
1154
1155
 
1155
1156
static void
1156
1157
make_2d_mipmap(struct gen_mipmap_state *ctx,
1157
 
               struct pipe_texture *pt,
 
1158
               struct pipe_resource *pt,
1158
1159
               uint face, uint baseLevel, uint lastLevel)
1159
1160
{
1160
1161
   struct pipe_context *pipe = ctx->pipe;
1161
 
   struct pipe_screen *screen = pipe->screen;
1162
1162
   const uint zslice = 0;
1163
1163
   uint dstLevel;
1164
1164
   
1170
1170
      struct pipe_transfer *srcTrans, *dstTrans;
1171
1171
      ubyte *srcMap, *dstMap;
1172
1172
      
1173
 
      srcTrans = screen->get_tex_transfer(screen, pt, face, srcLevel, zslice,
1174
 
                                          PIPE_TRANSFER_READ, 0, 0,
1175
 
                                          u_minify(pt->width0, srcLevel),
1176
 
                                          u_minify(pt->height0, srcLevel));
1177
 
      dstTrans = screen->get_tex_transfer(screen, pt, face, dstLevel, zslice,
1178
 
                                          PIPE_TRANSFER_WRITE, 0, 0,
1179
 
                                          u_minify(pt->width0, dstLevel),
1180
 
                                          u_minify(pt->height0, dstLevel));
 
1173
      srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
 
1174
                                   PIPE_TRANSFER_READ, 0, 0,
 
1175
                                   u_minify(pt->width0, srcLevel),
 
1176
                                   u_minify(pt->height0, srcLevel));
 
1177
      dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
 
1178
                                   PIPE_TRANSFER_WRITE, 0, 0,
 
1179
                                   u_minify(pt->width0, dstLevel),
 
1180
                                   u_minify(pt->height0, dstLevel));
1181
1181
 
1182
 
      srcMap = (ubyte *) screen->transfer_map(screen, srcTrans);
1183
 
      dstMap = (ubyte *) screen->transfer_map(screen, dstTrans);
 
1182
      srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
 
1183
      dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
1184
1184
 
1185
1185
      reduce_2d(pt->format,
1186
 
                srcTrans->width, srcTrans->height,
 
1186
                srcTrans->box.width, srcTrans->box.height,
1187
1187
                srcTrans->stride, srcMap,
1188
 
                dstTrans->width, dstTrans->height,
 
1188
                dstTrans->box.width, dstTrans->box.height,
1189
1189
                dstTrans->stride, dstMap);
1190
1190
 
1191
 
      screen->transfer_unmap(screen, srcTrans);
1192
 
      screen->transfer_unmap(screen, dstTrans);
 
1191
      pipe->transfer_unmap(pipe, srcTrans);
 
1192
      pipe->transfer_unmap(pipe, dstTrans);
1193
1193
 
1194
 
      screen->tex_transfer_destroy(srcTrans);
1195
 
      screen->tex_transfer_destroy(dstTrans);
 
1194
      pipe->transfer_destroy(pipe, srcTrans);
 
1195
      pipe->transfer_destroy(pipe, dstTrans);
1196
1196
   }
1197
1197
}
1198
1198
 
1199
1199
 
1200
1200
static void
1201
1201
make_3d_mipmap(struct gen_mipmap_state *ctx,
1202
 
               struct pipe_texture *pt,
 
1202
               struct pipe_resource *pt,
1203
1203
               uint face, uint baseLevel, uint lastLevel)
1204
1204
{
1205
1205
#if 0
1215
1215
      struct pipe_transfer *srcTrans, *dstTrans;
1216
1216
      ubyte *srcMap, *dstMap;
1217
1217
      
1218
 
      srcTrans = screen->get_tex_transfer(screen, pt, face, srcLevel, zslice,
 
1218
      srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice,
1219
1219
                                          PIPE_TRANSFER_READ, 0, 0,
1220
1220
                                          u_minify(pt->width0, srcLevel),
1221
1221
                                          u_minify(pt->height0, srcLevel));
1222
 
      dstTrans = screen->get_tex_transfer(screen, pt, face, dstLevel, zslice,
 
1222
      dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice,
1223
1223
                                          PIPE_TRANSFER_WRITE, 0, 0,
1224
1224
                                          u_minify(pt->width0, dstLevel),
1225
1225
                                          u_minify(pt->height0, dstLevel));
1226
1226
 
1227
 
      srcMap = (ubyte *) screen->transfer_map(screen, srcTrans);
1228
 
      dstMap = (ubyte *) screen->transfer_map(screen, dstTrans);
 
1227
      srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
 
1228
      dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
1229
1229
 
1230
1230
      reduce_3d(pt->format,
1231
1231
                srcTrans->width, srcTrans->height,
1233
1233
                dstTrans->width, dstTrans->height,
1234
1234
                dstTrans->stride, dstMap);
1235
1235
 
1236
 
      screen->transfer_unmap(screen, srcTrans);
1237
 
      screen->transfer_unmap(screen, dstTrans);
 
1236
      pipe->transfer_unmap(pipe, srcTrans);
 
1237
      pipe->transfer_unmap(pipe, dstTrans);
1238
1238
 
1239
 
      screen->tex_transfer_destroy(srcTrans);
1240
 
      screen->tex_transfer_destroy(dstTrans);
 
1239
      pipe->transfer_destroy(pipe, srcTrans);
 
1240
      pipe->transfer_destroy(pipe, dstTrans);
1241
1241
   }
1242
1242
#else
1243
1243
   (void) reduce_3d;
1247
1247
 
1248
1248
static void
1249
1249
fallback_gen_mipmap(struct gen_mipmap_state *ctx,
1250
 
                    struct pipe_texture *pt,
 
1250
                    struct pipe_resource *pt,
1251
1251
                    uint face, uint baseLevel, uint lastLevel)
1252
1252
{
1253
1253
   switch (pt->target) {
1255
1255
      make_1d_mipmap(ctx, pt, face, baseLevel, lastLevel);
1256
1256
      break;
1257
1257
   case PIPE_TEXTURE_2D:
 
1258
   case PIPE_TEXTURE_RECT:
1258
1259
   case PIPE_TEXTURE_CUBE:
1259
1260
      make_2d_mipmap(ctx, pt, face, baseLevel, lastLevel);
1260
1261
      break;
1295
1296
 
1296
1297
   /* rasterizer */
1297
1298
   memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
1298
 
   ctx->rasterizer.front_winding = PIPE_WINDING_CW;
1299
 
   ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
 
1299
   ctx->rasterizer.cull_face = PIPE_FACE_NONE;
1300
1300
   ctx->rasterizer.gl_rasterization_rules = 1;
1301
1301
 
1302
1302
   /* sampler state */
1307
1307
   ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
1308
1308
   ctx->sampler.normalized_coords = 1;
1309
1309
 
 
1310
   /* vertex elements state */
 
1311
   memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2);
 
1312
   for (i = 0; i < 2; i++) {
 
1313
      ctx->velem[i].src_offset = i * 4 * sizeof(float);
 
1314
      ctx->velem[i].instance_divisor = 0;
 
1315
      ctx->velem[i].vertex_buffer_index = 0;
 
1316
      ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
1317
   }
 
1318
 
1310
1319
   /* vertex shader - still needed to specify mapping from fragment
1311
1320
    * shader input semantics to vertex elements 
1312
1321
    */
1319
1328
   }
1320
1329
 
1321
1330
   /* fragment shader */
1322
 
   ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
1323
 
   ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE);
 
1331
   ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
 
1332
                                             TGSI_INTERPOLATE_LINEAR);
 
1333
   ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE,
 
1334
                                               TGSI_INTERPOLATE_LINEAR);
1324
1335
 
1325
1336
   /* vertex data that doesn't change */
1326
1337
   for (i = 0; i < 4; i++) {
1349
1360
 
1350
1361
   if (!ctx->vbuf) {
1351
1362
      ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
1352
 
                                     32,
1353
 
                                     PIPE_BUFFER_USAGE_VERTEX,
 
1363
                                     PIPE_BIND_VERTEX_BUFFER,
1354
1364
                                     max_slots * sizeof ctx->vertices);
1355
1365
   }
1356
1366
   
1411
1421
 
1412
1422
   offset = get_next_slot( ctx );
1413
1423
 
1414
 
   pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
 
1424
   pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
1415
1425
                               offset, sizeof(ctx->vertices), ctx->vertices);
1416
1426
 
1417
1427
   return offset;
1431
1441
   pipe->delete_fs_state(pipe, ctx->fs2d);
1432
1442
   pipe->delete_fs_state(pipe, ctx->fsCube);
1433
1443
 
1434
 
   pipe_buffer_reference(&ctx->vbuf, NULL);
 
1444
   pipe_resource_reference(&ctx->vbuf, NULL);
1435
1445
 
1436
1446
   FREE(ctx);
1437
1447
}
1443
1453
 */
1444
1454
void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
1445
1455
{
1446
 
   pipe_buffer_reference(&ctx->vbuf, NULL);
 
1456
   pipe_resource_reference(&ctx->vbuf, NULL);
1447
1457
   ctx->vbuf_slot = 0;
1448
1458
1449
1459
 
1452
1462
 * Generate mipmap images.  It's assumed all needed texture memory is
1453
1463
 * already allocated.
1454
1464
 *
1455
 
 * \param pt  the texture to generate mipmap levels for
 
1465
 * \param psv  the sampler view to the texture to generate mipmap levels for
1456
1466
 * \param face  which cube face to generate mipmaps for (0 for non-cube maps)
1457
1467
 * \param baseLevel  the first mipmap level to use as a src
1458
1468
 * \param lastLevel  the last mipmap level to generate
1461
1471
 */
1462
1472
void
1463
1473
util_gen_mipmap(struct gen_mipmap_state *ctx,
1464
 
                struct pipe_texture *pt,
 
1474
                struct pipe_sampler_view *psv,
1465
1475
                uint face, uint baseLevel, uint lastLevel, uint filter)
1466
1476
{
1467
1477
   struct pipe_context *pipe = ctx->pipe;
1468
1478
   struct pipe_screen *screen = pipe->screen;
1469
1479
   struct pipe_framebuffer_state fb;
 
1480
   struct pipe_resource *pt = psv->texture;
1470
1481
   void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
1471
1482
   uint dstLevel;
1472
1483
   uint zslice = 0;
1484
1495
          filter == PIPE_TEX_FILTER_NEAREST);
1485
1496
 
1486
1497
   /* check if we can render in the texture's format */
1487
 
   if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D,
1488
 
                                    PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
 
1498
   if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
 
1499
                                    pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) {
1489
1500
      fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
1490
1501
      return;
1491
1502
   }
1495
1506
   cso_save_depth_stencil_alpha(ctx->cso);
1496
1507
   cso_save_rasterizer(ctx->cso);
1497
1508
   cso_save_samplers(ctx->cso);
1498
 
   cso_save_sampler_textures(ctx->cso);
 
1509
   cso_save_fragment_sampler_views(ctx->cso);
1499
1510
   cso_save_framebuffer(ctx->cso);
1500
1511
   cso_save_fragment_shader(ctx->cso);
1501
1512
   cso_save_vertex_shader(ctx->cso);
1502
1513
   cso_save_viewport(ctx->cso);
1503
1514
   cso_save_clip(ctx->cso);
 
1515
   cso_save_vertex_elements(ctx->cso);
1504
1516
 
1505
1517
   /* bind our state */
1506
1518
   cso_set_blend(ctx->cso, &ctx->blend);
1507
1519
   cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
1508
1520
   cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
1509
1521
   cso_set_clip(ctx->cso, &ctx->clip);
 
1522
   cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
1510
1523
 
1511
1524
   cso_set_fragment_shader_handle(ctx->cso, fs);
1512
1525
   cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
1529
1542
 
1530
1543
      struct pipe_surface *surf = 
1531
1544
         screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
1532
 
                                 PIPE_BUFFER_USAGE_GPU_WRITE);
 
1545
                                 PIPE_BIND_RENDER_TARGET);
1533
1546
 
1534
1547
      /*
1535
1548
       * Setup framebuffer / dest surface
1562
1575
      cso_single_sampler(ctx->cso, 0, &ctx->sampler);
1563
1576
      cso_single_sampler_done(ctx->cso);
1564
1577
 
1565
 
      cso_set_sampler_textures(ctx->cso, 1, &pt);
 
1578
      cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
1566
1579
 
1567
1580
      /* quad coords in clip coords */
1568
1581
      offset = set_vertex_data(ctx,
1587
1600
   cso_restore_depth_stencil_alpha(ctx->cso);
1588
1601
   cso_restore_rasterizer(ctx->cso);
1589
1602
   cso_restore_samplers(ctx->cso);
1590
 
   cso_restore_sampler_textures(ctx->cso);
 
1603
   cso_restore_fragment_sampler_views(ctx->cso);
1591
1604
   cso_restore_framebuffer(ctx->cso);
1592
1605
   cso_restore_fragment_shader(ctx->cso);
1593
1606
   cso_restore_vertex_shader(ctx->cso);
1594
1607
   cso_restore_viewport(ctx->cso);
1595
1608
   cso_restore_clip(ctx->cso);
 
1609
   cso_restore_vertex_elements(ctx->cso);
1596
1610
}