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

« back to all changes in this revision

Viewing changes to src/gallium/state_trackers/python/p_context.i

  • 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:
51
51
   void set_blend( const struct pipe_blend_state *state ) {
52
52
      cso_set_blend($self->cso, state);
53
53
   }
54
 
   
 
54
 
55
55
   void set_fragment_sampler( unsigned index, const struct pipe_sampler_state *state ) {
56
56
      cso_single_sampler($self->cso, index, state);
57
57
      cso_single_sampler_done($self->cso);
127
127
      $self->gs = gs;
128
128
   }
129
129
 
 
130
   struct pipe_sampler_view *
 
131
   create_sampler_view(struct pipe_resource *texture,
 
132
                       enum pipe_format format = PIPE_FORMAT_NONE,
 
133
                       unsigned first_level = 0,
 
134
                       unsigned last_level = ~0,
 
135
                       unsigned swizzle_r = 0,
 
136
                       unsigned swizzle_g = 1,
 
137
                       unsigned swizzle_b = 2,
 
138
                       unsigned swizzle_a = 3)
 
139
   {
 
140
      struct pipe_context *pipe = $self->pipe;
 
141
      struct pipe_sampler_view templat;
 
142
 
 
143
      memset(&templat, 0, sizeof templat);
 
144
      if (format == PIPE_FORMAT_NONE) {
 
145
         templat.format = texture->format;
 
146
      } else {
 
147
         templat.format = format;
 
148
      }
 
149
      templat.last_level = MIN2(last_level, texture->last_level);
 
150
      templat.first_level = first_level;
 
151
      templat.last_level = last_level;
 
152
      templat.swizzle_r = swizzle_r;
 
153
      templat.swizzle_g = swizzle_g;
 
154
      templat.swizzle_b = swizzle_b;
 
155
      templat.swizzle_a = swizzle_a;
 
156
 
 
157
      return pipe->create_sampler_view(pipe, texture, &templat);
 
158
   }
 
159
 
 
160
   void
 
161
   sampler_view_destroy(struct pipe_context *ctx,
 
162
                        struct pipe_sampler_view *view)
 
163
   {
 
164
      struct pipe_context *pipe = $self->pipe;
 
165
 
 
166
      pipe->sampler_view_destroy(pipe, view);
 
167
   }
 
168
 
130
169
   /*
131
170
    * Parameter-like state (or properties)
132
171
    */
144
183
   }
145
184
 
146
185
   void set_constant_buffer(unsigned shader, unsigned index,
147
 
                            struct pipe_buffer *buffer ) 
 
186
                            struct pipe_resource *buffer ) 
148
187
   {
149
188
      $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
150
189
   }
167
206
      cso_set_viewport($self->cso, state);
168
207
   }
169
208
 
 
209
   void set_fragment_sampler_view(unsigned index,
 
210
                                  struct pipe_sampler_view *view)
 
211
   {
 
212
      pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view);
 
213
 
 
214
      $self->pipe->set_fragment_sampler_views($self->pipe,
 
215
                                              PIPE_MAX_SAMPLERS,
 
216
                                              $self->fragment_sampler_views);
 
217
   }
 
218
 
 
219
   void set_vertex_sampler_view(unsigned index,
 
220
                                struct pipe_sampler_view *view)
 
221
   {
 
222
      pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view);
 
223
 
 
224
      $self->pipe->set_vertex_sampler_views($self->pipe,
 
225
                                            PIPE_MAX_VERTEX_SAMPLERS,
 
226
                                            $self->vertex_sampler_views);
 
227
   }
 
228
 
170
229
   void set_fragment_sampler_texture(unsigned index,
171
 
                                     struct pipe_texture *texture) {
 
230
                                     struct pipe_resource *texture) {
 
231
      struct pipe_sampler_view templ;
 
232
 
172
233
      if(!texture)
173
234
         texture = $self->default_texture;
174
 
      pipe_texture_reference(&$self->fragment_sampler_textures[index], texture);
175
 
      $self->pipe->set_fragment_sampler_textures($self->pipe,
176
 
                                                 PIPE_MAX_SAMPLERS,
177
 
                                                 $self->fragment_sampler_textures);
 
235
      pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL);
 
236
      u_sampler_view_default_template(&templ,
 
237
                                      texture,
 
238
                                      texture->format);
 
239
      $self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
 
240
                                                                              texture,
 
241
                                                                              &templ);
 
242
      $self->pipe->set_fragment_sampler_views($self->pipe,
 
243
                                              PIPE_MAX_SAMPLERS,
 
244
                                              $self->fragment_sampler_views);
178
245
   }
179
246
 
180
247
   void set_vertex_sampler_texture(unsigned index,
181
 
                                   struct pipe_texture *texture) {
 
248
                                   struct pipe_resource *texture) {
 
249
      struct pipe_sampler_view templ;
 
250
 
182
251
      if(!texture)
183
252
         texture = $self->default_texture;
184
 
      pipe_texture_reference(&$self->vertex_sampler_textures[index], texture);
185
 
      $self->pipe->set_vertex_sampler_textures($self->pipe,
186
 
                                               PIPE_MAX_VERTEX_SAMPLERS,
187
 
                                               $self->vertex_sampler_textures);
 
253
      pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL);
 
254
      u_sampler_view_default_template(&templ,
 
255
                                      texture,
 
256
                                      texture->format);
 
257
      $self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
 
258
                                                                            texture,
 
259
                                                                            &templ);
 
260
      
 
261
      $self->pipe->set_vertex_sampler_views($self->pipe,
 
262
                                            PIPE_MAX_VERTEX_SAMPLERS,
 
263
                                            $self->vertex_sampler_views);
188
264
   }
189
265
 
190
266
   void set_vertex_buffer(unsigned index,
191
267
                          unsigned stride, 
192
268
                          unsigned max_index,
193
269
                          unsigned buffer_offset,
194
 
                          struct pipe_buffer *buffer)
 
270
                          struct pipe_resource *buffer)
195
271
   {
196
272
      unsigned i;
197
273
      struct pipe_vertex_buffer state;
213
289
                                      $self->vertex_buffers);
214
290
   }
215
291
 
 
292
   void set_index_buffer(unsigned index_size,
 
293
                         unsigned offset,
 
294
                         struct pipe_resource *buffer)
 
295
   {
 
296
      struct pipe_index_buffer ib;
 
297
 
 
298
      memset(&ib, 0, sizeof(ib));
 
299
      ib.index_size = index_size;
 
300
      ib.offset = offset;
 
301
      ib.buffer = buffer;
 
302
 
 
303
      $self->pipe->set_index_buffer($self->pipe, &ib);
 
304
   }
 
305
 
216
306
   void set_vertex_element(unsigned index,
217
307
                           const struct pipe_vertex_element *element) 
218
308
   {
222
312
   void set_vertex_elements(unsigned num) 
223
313
   {
224
314
      $self->num_vertex_elements = num;
225
 
      $self->pipe->set_vertex_elements($self->pipe, 
226
 
                                       $self->num_vertex_elements, 
227
 
                                       $self->vertex_elements);
 
315
      cso_set_vertex_elements($self->cso,
 
316
                              $self->num_vertex_elements, 
 
317
                              $self->vertex_elements);
228
318
   }
229
319
 
230
320
   /*
232
322
    */
233
323
   
234
324
   void draw_arrays(unsigned mode, unsigned start, unsigned count) {
235
 
      $self->pipe->draw_arrays($self->pipe, mode, start, count);
236
 
   }
237
 
 
238
 
   void draw_elements( struct pipe_buffer *indexBuffer,
239
 
                       unsigned indexSize,
240
 
                       unsigned mode, unsigned start, unsigned count) 
241
 
   {
242
 
      $self->pipe->draw_elements($self->pipe, 
243
 
                                 indexBuffer, 
244
 
                                 indexSize, 
245
 
                                 mode, start, count);
246
 
   }
247
 
 
248
 
   void draw_range_elements( struct pipe_buffer *indexBuffer,
249
 
                             unsigned indexSize, unsigned minIndex, unsigned maxIndex,
250
 
                             unsigned mode, unsigned start, unsigned count)
251
 
   {
252
 
      $self->pipe->draw_range_elements($self->pipe, 
253
 
                                       indexBuffer, 
254
 
                                       indexSize, minIndex, maxIndex,
255
 
                                       mode, start, count);
 
325
      util_draw_arrays($self->pipe, mode, start, count);
 
326
   }
 
327
 
 
328
   void draw_vbo(const struct pipe_draw_info *info)
 
329
   {
 
330
      $self->pipe->draw_vbo($self->pipe, info);
256
331
   }
257
332
 
258
333
   void draw_vertices(unsigned prim,
262
337
   {
263
338
      struct pipe_context *pipe = $self->pipe;
264
339
      struct pipe_screen *screen = pipe->screen;
265
 
      struct pipe_buffer *vbuf;
 
340
      struct pipe_resource *vbuf;
 
341
      struct pipe_transfer *transfer;
 
342
      struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
 
343
      struct pipe_vertex_buffer vbuffer;
266
344
      float *map;
267
345
      unsigned size;
 
346
      unsigned i;
268
347
 
269
348
      size = num_verts * num_attribs * 4 * sizeof(float);
270
349
 
271
350
      vbuf = pipe_buffer_create(screen,
272
 
                                32,
273
 
                                PIPE_BUFFER_USAGE_VERTEX, 
 
351
                                PIPE_BIND_VERTEX_BUFFER, 
274
352
                                size);
275
353
      if(!vbuf)
276
354
         goto error1;
277
 
      
278
 
      map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
 
355
 
 
356
      map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
279
357
      if (!map)
280
358
         goto error2;
281
359
      memcpy(map, vertices, size);
282
 
      pipe_buffer_unmap(screen, vbuf);
283
 
      
284
 
      util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs);
285
 
      
 
360
      pipe_buffer_unmap(pipe, vbuf, transfer);
 
361
 
 
362
      cso_save_vertex_elements($self->cso);
 
363
 
 
364
      /* tell pipe about the vertex attributes */
 
365
      for (i = 0; i < num_attribs; i++) {
 
366
         velements[i].src_offset = i * 4 * sizeof(float);
 
367
         velements[i].instance_divisor = 0;
 
368
         velements[i].vertex_buffer_index = 0;
 
369
         velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
370
      }
 
371
      cso_set_vertex_elements($self->cso, num_attribs, velements);
 
372
 
 
373
      /* tell pipe about the vertex buffer */
 
374
      memset(&vbuffer, 0, sizeof(vbuffer));
 
375
      vbuffer.buffer = vbuf;
 
376
      vbuffer.stride = num_attribs * 4 * sizeof(float);  /* vertex size */
 
377
      vbuffer.buffer_offset = 0;
 
378
      vbuffer.max_index = num_verts - 1;
 
379
      pipe->set_vertex_buffers(pipe, 1, &vbuffer);
 
380
 
 
381
      /* draw */
 
382
      util_draw_arrays(pipe, prim, 0, num_verts);
 
383
 
 
384
      cso_restore_vertex_elements($self->cso);
 
385
 
286
386
error2:
287
 
      pipe_buffer_reference(&vbuf, NULL);
 
387
      pipe_resource_reference(&vbuf, NULL);
288
388
error1:
289
389
      ;
290
390
   }
291
391
   
292
392
   void
 
393
   clear(unsigned buffers, const float *rgba, double depth = 0.0f,
 
394
         unsigned stencil = 0)
 
395
   {
 
396
      $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
 
397
   }
 
398
 
 
399
   void
293
400
   flush(unsigned flags = 0) {
294
401
      struct pipe_fence_handle *fence = NULL; 
295
402
      $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
303
410
   /*
304
411
    * Surface functions
305
412
    */
306
 
   
307
 
   void surface_copy(struct st_surface *dst,
308
 
                     unsigned destx, unsigned desty,
309
 
                     struct st_surface *src,
310
 
                     unsigned srcx, unsigned srcy,
311
 
                     unsigned width, unsigned height) 
312
 
   {
313
 
      struct pipe_surface *_dst = NULL;
314
 
      struct pipe_surface *_src = NULL;
315
 
      
316
 
      _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
317
 
      if(!_dst)
318
 
         SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
319
 
 
320
 
      _src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ);
321
 
      if(!_src)
322
 
         SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading");
323
 
      
324
 
      $self->pipe->surface_copy($self->pipe, _dst, destx, desty, _src, srcx, srcy, width, height);
325
 
      
326
 
   fail:
327
 
      pipe_surface_reference(&_src, NULL);
328
 
      pipe_surface_reference(&_dst, NULL);
329
 
   }
330
 
 
331
 
   void surface_fill(struct st_surface *dst,
332
 
                     unsigned x, unsigned y,
333
 
                     unsigned width, unsigned height,
334
 
                     unsigned value) 
335
 
   {
336
 
      struct pipe_surface *_dst = NULL;
337
 
      
338
 
      _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
339
 
      if(!_dst)
340
 
         SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
341
 
 
342
 
      $self->pipe->surface_fill($self->pipe, _dst, x, y, width, height, value);
343
 
      
344
 
   fail:
345
 
      pipe_surface_reference(&_dst, NULL);
346
 
   }
347
 
 
348
 
   void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
349
 
              unsigned stencil = 0)
350
 
   {
351
 
      $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
 
413
 
 
414
   void resource_copy_region(struct pipe_resource *dst,
 
415
                             struct pipe_subresource subdst,
 
416
                             unsigned dstx, unsigned dsty, unsigned dstz,
 
417
                             struct pipe_resource *src,
 
418
                             struct pipe_subresource subsrc,
 
419
                             unsigned srcx, unsigned srcy, unsigned srcz,
 
420
                             unsigned width, unsigned height)
 
421
   {
 
422
      $self->pipe->resource_copy_region($self->pipe,
 
423
                                        dst, subdst, dstx, dsty, dstz,
 
424
                                        src, subsrc, srcx, srcy, srcz,
 
425
                                        width, height);
 
426
   }
 
427
 
 
428
 
 
429
   void clear_render_target(struct st_surface *dst,
 
430
                            float *rgba,
 
431
                            unsigned x, unsigned y,
 
432
                            unsigned width, unsigned height)
 
433
   {
 
434
      struct pipe_surface *_dst = NULL;
 
435
 
 
436
     _dst = st_pipe_surface(dst, PIPE_BIND_RENDER_TARGET);
 
437
      if(!_dst)
 
438
         SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
 
439
 
 
440
      $self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height);
 
441
 
 
442
   fail:
 
443
      pipe_surface_reference(&_dst, NULL);
 
444
   }
 
445
 
 
446
   void clear_depth_stencil(struct st_surface *dst,
 
447
                            unsigned clear_flags,
 
448
                            double depth,
 
449
                            unsigned stencil,
 
450
                            unsigned x, unsigned y,
 
451
                            unsigned width, unsigned height)
 
452
   {
 
453
      struct pipe_surface *_dst = NULL;
 
454
 
 
455
     _dst = st_pipe_surface(dst, PIPE_BIND_DEPTH_STENCIL);
 
456
      if(!_dst)
 
457
         SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
 
458
 
 
459
      $self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil,
 
460
                                       x, y, width, height);
 
461
 
 
462
   fail:
 
463
      pipe_surface_reference(&_dst, NULL);
 
464
   }
 
465
 
 
466
   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
 
467
   void
 
468
   surface_read_raw(struct st_surface *surface,
 
469
                    unsigned x, unsigned y, unsigned w, unsigned h,
 
470
                    char **STRING, int *LENGTH)
 
471
   {
 
472
      struct pipe_resource *texture = surface->texture;
 
473
      struct pipe_context *pipe = $self->pipe;
 
474
      struct pipe_transfer *transfer;
 
475
      unsigned stride;
 
476
 
 
477
      stride = util_format_get_stride(texture->format, w);
 
478
      *LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
 
479
      *STRING = (char *) malloc(*LENGTH);
 
480
      if(!*STRING)
 
481
         return;
 
482
 
 
483
      transfer = pipe_get_transfer(pipe,
 
484
                                   surface->texture,
 
485
                                   surface->face,
 
486
                                   surface->level,
 
487
                                   surface->zslice,
 
488
                                   PIPE_TRANSFER_READ,
 
489
                                   x, y, w, h);
 
490
      if(transfer) {
 
491
         pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
 
492
         pipe->transfer_destroy(pipe, transfer);
 
493
      }
 
494
   }
 
495
 
 
496
   %cstring_input_binary(const char *STRING, unsigned LENGTH);
 
497
   void
 
498
   surface_write_raw(struct st_surface *surface,
 
499
                     unsigned x, unsigned y, unsigned w, unsigned h,
 
500
                     const char *STRING, unsigned LENGTH, unsigned stride = 0)
 
501
   {
 
502
      struct pipe_resource *texture = surface->texture;
 
503
      struct pipe_context *pipe = $self->pipe;
 
504
      struct pipe_transfer *transfer;
 
505
 
 
506
      if(stride == 0)
 
507
         stride = util_format_get_stride(texture->format, w);
 
508
 
 
509
      if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
 
510
         SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
 
511
 
 
512
      transfer = pipe_get_transfer(pipe,
 
513
                                   surface->texture,
 
514
                                   surface->face,
 
515
                                   surface->level,
 
516
                                   surface->zslice,
 
517
                                   PIPE_TRANSFER_WRITE,
 
518
                                   x, y, w, h);
 
519
      if(!transfer)
 
520
         SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
 
521
 
 
522
      pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
 
523
      pipe->transfer_destroy(pipe, transfer);
 
524
 
 
525
   fail:
 
526
      return;
 
527
   }
 
528
 
 
529
   void
 
530
   surface_read_rgba(struct st_surface *surface,
 
531
                     unsigned x, unsigned y, unsigned w, unsigned h,
 
532
                     float *rgba)
 
533
   {
 
534
      struct pipe_context *pipe = $self->pipe;
 
535
      struct pipe_transfer *transfer;
 
536
      transfer = pipe_get_transfer(pipe,
 
537
                                   surface->texture,
 
538
                                   surface->face,
 
539
                                   surface->level,
 
540
                                   surface->zslice,
 
541
                                   PIPE_TRANSFER_READ,
 
542
                                   x, y, w, h);
 
543
      if(transfer) {
 
544
         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
 
545
         pipe->transfer_destroy(pipe, transfer);
 
546
      }
 
547
   }
 
548
 
 
549
   void
 
550
   surface_write_rgba(struct st_surface *surface,
 
551
                      unsigned x, unsigned y, unsigned w, unsigned h,
 
552
                      const float *rgba)
 
553
   {
 
554
      struct pipe_context *pipe = $self->pipe;
 
555
      struct pipe_transfer *transfer;
 
556
      transfer = pipe_get_transfer(pipe,
 
557
                                   surface->texture,
 
558
                                   surface->face,
 
559
                                   surface->level,
 
560
                                   surface->zslice,
 
561
                                   PIPE_TRANSFER_WRITE,
 
562
                                   x, y, w, h);
 
563
      if(transfer) {
 
564
         pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
 
565
         pipe->transfer_destroy(pipe, transfer);
 
566
      }
 
567
   }
 
568
 
 
569
   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
 
570
   void
 
571
   surface_read_rgba8(struct st_surface *surface,
 
572
                      unsigned x, unsigned y, unsigned w, unsigned h,
 
573
                      char **STRING, int *LENGTH)
 
574
   {
 
575
      struct pipe_context *pipe = $self->pipe;
 
576
      struct pipe_transfer *transfer;
 
577
      float *rgba;
 
578
      unsigned char *rgba8;
 
579
      unsigned i, j, k;
 
580
 
 
581
      *LENGTH = 0;
 
582
      *STRING = NULL;
 
583
 
 
584
      if (!surface)
 
585
         return;
 
586
 
 
587
      *LENGTH = h*w*4;
 
588
      *STRING = (char *) malloc(*LENGTH);
 
589
      if(!*STRING)
 
590
         return;
 
591
 
 
592
      rgba = malloc(h*w*4*sizeof(float));
 
593
      if(!rgba)
 
594
         return;
 
595
 
 
596
      rgba8 = (unsigned char *) *STRING;
 
597
 
 
598
      transfer = pipe_get_transfer(pipe,
 
599
                                   surface->texture,
 
600
                                   surface->face,
 
601
                                   surface->level,
 
602
                                   surface->zslice,
 
603
                                   PIPE_TRANSFER_READ,
 
604
                                   x, y, w, h);
 
605
      if(transfer) {
 
606
         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
 
607
         for(j = 0; j < h; ++j) {
 
608
            for(i = 0; i < w; ++i)
 
609
               for(k = 0; k <4; ++k)
 
610
                  rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
 
611
         }
 
612
         pipe->transfer_destroy(pipe, transfer);
 
613
      }
 
614
 
 
615
      free(rgba);
 
616
   }
 
617
 
 
618
   void
 
619
   surface_read_z(struct st_surface *surface,
 
620
                  unsigned x, unsigned y, unsigned w, unsigned h,
 
621
                  unsigned *z)
 
622
   {
 
623
      struct pipe_context *pipe = $self->pipe;
 
624
      struct pipe_transfer *transfer;
 
625
      transfer = pipe_get_transfer(pipe,
 
626
                                   surface->texture,
 
627
                                   surface->face,
 
628
                                   surface->level,
 
629
                                   surface->zslice,
 
630
                                   PIPE_TRANSFER_READ,
 
631
                                   x, y, w, h);
 
632
      if(transfer) {
 
633
         pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
 
634
         pipe->transfer_destroy(pipe, transfer);
 
635
      }
 
636
   }
 
637
 
 
638
   void
 
639
   surface_write_z(struct st_surface *surface,
 
640
                   unsigned x, unsigned y, unsigned w, unsigned h,
 
641
                   const unsigned *z)
 
642
   {
 
643
      struct pipe_context *pipe = $self->pipe;
 
644
      struct pipe_transfer *transfer;
 
645
      transfer = pipe_get_transfer(pipe,
 
646
                                   surface->texture,
 
647
                                   surface->face,
 
648
                                   surface->level,
 
649
                                   surface->zslice,
 
650
                                   PIPE_TRANSFER_WRITE,
 
651
                                   x, y, w, h);
 
652
      if(transfer) {
 
653
         pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
 
654
         pipe->transfer_destroy(pipe, transfer);
 
655
      }
 
656
   }
 
657
 
 
658
   void
 
659
   surface_sample_rgba(struct st_surface *surface,
 
660
                       float *rgba,
 
661
                       int norm = 0)
 
662
   {
 
663
      st_sample_surface($self->pipe, surface, rgba, norm != 0);
 
664
   }
 
665
 
 
666
   unsigned
 
667
   surface_compare_rgba(struct st_surface *surface,
 
668
                        unsigned x, unsigned y, unsigned w, unsigned h,
 
669
                        const float *rgba, float tol = 0.0)
 
670
   {
 
671
      struct pipe_context *pipe = $self->pipe;
 
672
      struct pipe_transfer *transfer;
 
673
      float *rgba2;
 
674
      const float *p1;
 
675
      const float *p2;
 
676
      unsigned i, j, n;
 
677
 
 
678
      rgba2 = MALLOC(h*w*4*sizeof(float));
 
679
      if(!rgba2)
 
680
         return ~0;
 
681
 
 
682
      transfer = pipe_get_transfer(pipe,
 
683
                                   surface->texture,
 
684
                                   surface->face,
 
685
                                   surface->level,
 
686
                                   surface->zslice,
 
687
                                   PIPE_TRANSFER_READ,
 
688
                                   x, y, w, h);
 
689
      if(!transfer) {
 
690
         FREE(rgba2);
 
691
         return ~0;
 
692
      }
 
693
 
 
694
      pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
 
695
      pipe->transfer_destroy(pipe, transfer);
 
696
 
 
697
      p1 = rgba;
 
698
      p2 = rgba2;
 
699
      n = 0;
 
700
      for(i = h*w; i; --i) {
 
701
         unsigned differs = 0;
 
702
         for(j = 4; j; --j) {
 
703
            float delta = *p2++ - *p1++;
 
704
            if (delta < -tol || delta > tol)
 
705
                differs = 1;
 
706
         }
 
707
         n += differs;
 
708
      }
 
709
 
 
710
      FREE(rgba2);
 
711
 
 
712
      return n;
 
713
   }
 
714
 
 
715
   %cstring_input_binary(const char *STRING, unsigned LENGTH);
 
716
   void
 
717
   transfer_inline_write(struct pipe_resource *resource,
 
718
                         struct pipe_subresource *sr,
 
719
                         unsigned usage,
 
720
                         const struct pipe_box *box,
 
721
                         const char *STRING, unsigned LENGTH,
 
722
                         unsigned stride,
 
723
                         unsigned slice_stride)
 
724
   {
 
725
      struct pipe_context *pipe = $self->pipe;
 
726
 
 
727
      pipe->transfer_inline_write(pipe, resource, *sr, usage, box, STRING, stride, slice_stride);
 
728
   }
 
729
 
 
730
   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
 
731
   void buffer_read(struct pipe_resource *buffer,
 
732
                    char **STRING, int *LENGTH)
 
733
   {
 
734
      struct pipe_context *pipe = $self->pipe;
 
735
 
 
736
      assert(buffer->target == PIPE_BUFFER);
 
737
 
 
738
      *LENGTH = buffer->width0;
 
739
      *STRING = (char *) malloc(buffer->width0);
 
740
      if(!*STRING)
 
741
         return;
 
742
 
 
743
      pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING);
 
744
   }
 
745
 
 
746
   void buffer_write(struct pipe_resource *buffer,
 
747
                     const char *STRING, unsigned LENGTH, unsigned offset = 0)
 
748
   {
 
749
      struct pipe_context *pipe = $self->pipe;
 
750
 
 
751
      assert(buffer->target == PIPE_BUFFER);
 
752
 
 
753
      if(offset > buffer->width0)
 
754
         SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
 
755
 
 
756
      if(offset + LENGTH > buffer->width0)
 
757
         SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
 
758
 
 
759
      pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING);
 
760
 
 
761
fail:
 
762
      return;
352
763
   }
353
764
 
354
765
};