X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fstate_trackers%2Fpython%2Fp_texture.i;h=ae506944c4513010e297b61c1581671952db5dcf;hb=1318848f782cce716d6376ca13aebf68b728e24c;hp=08ba0ebe4d0b566f93474eabedaf70e7dd9b88cb;hpb=4b7a84a36108eff8f17cbdf2c511593eb3260fd2;p=mesa.git diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 08ba0ebe4d0..ae506944c45 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -33,200 +33,124 @@ */ -%nodefaultctor pipe_texture; -%nodefaultctor pipe_surface; -%nodefaultctor st_buffer; +%nodefaultctor pipe_resource; +%nodefaultctor st_surface; -%nodefaultdtor pipe_texture; -%nodefaultdtor pipe_surface; -%nodefaultdtor st_buffer; +%nodefaultdtor pipe_resource; +%nodefaultdtor st_surface; -%ignore pipe_texture::screen; +%ignore pipe_resource::screen; -%ignore pipe_surface::winsys; -%immutable pipe_surface::texture; -%immutable pipe_surface::buffer; +%immutable st_surface::texture; +%immutable st_surface::face; +%immutable st_surface::level; +%immutable st_surface::zslice; -%newobject pipe_texture::get_surface; +%newobject pipe_resource::get_surface; +/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */ +%rename(read) read_; +%rename(write) write_; -%extend pipe_texture { - - ~pipe_texture() { - struct pipe_texture *ptr = $self; - pipe_texture_reference(&ptr, NULL); +%extend pipe_resource { + + ~pipe_resource() { + struct pipe_resource *ptr = $self; + pipe_resource_reference(&ptr, NULL); } - + unsigned get_width(unsigned level=0) { - return $self->width[level]; + return u_minify($self->width0, level); } - + unsigned get_height(unsigned level=0) { - return $self->height[level]; + return u_minify($self->height0, level); } - + unsigned get_depth(unsigned level=0) { - return $self->depth[level]; - } - - unsigned get_nblocksx(unsigned level=0) { - return $self->nblocksx[level]; - } - - unsigned get_nblocksy(unsigned level=0) { - return $self->nblocksy[level]; + return u_minify($self->depth0, level); } - + /** Get a surface which is a "view" into a texture */ - struct pipe_surface * - get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0, unsigned usage=0 ) + struct st_surface * + get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0) { - struct pipe_screen *screen = $self->screen; - return screen->get_tex_surface(screen, $self, face, level, zslice, usage); - } - -}; + struct st_surface *surface; + if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U)) + SWIG_exception(SWIG_ValueError, "face out of bounds"); + if(level > $self->last_level) + SWIG_exception(SWIG_ValueError, "level out of bounds"); + if(zslice >= u_minify($self->depth0, level)) + SWIG_exception(SWIG_ValueError, "zslice out of bounds"); -%extend pipe_surface { - - ~pipe_surface() { - struct pipe_surface *ptr = $self; - pipe_surface_reference(&ptr, NULL); - } - - // gets mapped to pipe_surface_map automatically - void * map( unsigned flags ); + surface = CALLOC_STRUCT(st_surface); + if(!surface) + return NULL; - // gets mapped to pipe_surface_unmap automatically - void unmap( void ); + pipe_resource_reference(&surface->texture, $self); + surface->face = face; + surface->level = level; + surface->zslice = zslice; - void - get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char *raw, unsigned stride) { - pipe_get_tile_raw($self, x, y, w, h, raw, stride); - } + return surface; - void - put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *raw, unsigned stride) { - pipe_put_tile_raw($self, x, y, w, h, raw, stride); + fail: + return NULL; } - void - get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) { - pipe_get_tile_rgba($self, x, y, w, h, rgba); + unsigned __len__(void) + { + assert($self->target == PIPE_BUFFER); + assert(p_atomic_read(&$self->reference.count) > 0); + return $self->width0; } - void - put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) { - pipe_put_tile_rgba($self, x, y, w, h, rgba); - } +}; - void - get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) { - pipe_get_tile_z($self, x, y, w, h, z); - } +struct st_surface +{ + %immutable; - void - put_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) { - pipe_put_tile_z($self, x, y, w, h, z); - } - - void - sample_rgba(float *rgba) { - st_sample_surface($self, rgba); - } - - unsigned - compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) - { - float *rgba2; - const float *p1; - const float *p2; - unsigned i, j, n; - - rgba2 = MALLOC(h*w*4*sizeof(float)); - if(!rgba2) - return ~0; - - pipe_get_tile_rgba($self, x, y, w, h, rgba2); - - p1 = rgba; - p2 = rgba2; - n = 0; - for(i = h*w; i; --i) { - unsigned differs = 0; - for(j = 4; j; --j) { - float delta = *p2++ - *p1++; - if (delta < -tol || delta > tol) - differs = 1; - } - n += differs; - } - - FREE(rgba2); - - return n; - } + struct pipe_resource *texture; + unsigned face; + unsigned level; + unsigned zslice; }; -struct st_buffer { -}; +%extend st_surface { -%extend st_buffer { - - ~st_buffer() { - st_buffer_destroy($self); + %immutable; + + unsigned format; + unsigned width; + unsigned height; + + ~st_surface() { + pipe_resource_reference(&$self->texture, NULL); + FREE($self); } - - unsigned __len__(void) + + +}; + +%{ + static enum pipe_format + st_surface_format_get(struct st_surface *surface) { - assert($self->buffer->refcount); - return $self->buffer->size; + return surface->texture->format; } - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void read(char **STRING, int *LENGTH) + static unsigned + st_surface_width_get(struct st_surface *surface) { - struct pipe_screen *screen = $self->st_dev->screen; - const char *map; - - assert($self->buffer->refcount); - - *LENGTH = $self->buffer->size; - *STRING = (char *) malloc($self->buffer->size); - if(!*STRING) - return; - - map = pipe_buffer_map(screen, $self->buffer, PIPE_BUFFER_USAGE_CPU_READ); - if(map) { - memcpy(*STRING, map, $self->buffer->size); - pipe_buffer_unmap(screen, $self->buffer); - } + return u_minify(surface->texture->width0, surface->level); } - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void write(const char *STRING, unsigned LENGTH, unsigned offset = 0) + static unsigned + st_surface_height_get(struct st_surface *surface) { - struct pipe_screen *screen = $self->st_dev->screen; - char *map; - - assert($self->buffer->refcount); - - if(offset > $self->buffer->size) { - PyErr_SetString(PyExc_ValueError, "offset must be smaller than buffer size"); - return; - } - - if(offset + LENGTH > $self->buffer->size) { - PyErr_SetString(PyExc_ValueError, "data length must fit inside the buffer"); - return; - } - - map = pipe_buffer_map(screen, $self->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); - if(map) { - memcpy(map + offset, STRING, LENGTH); - pipe_buffer_unmap(screen, $self->buffer); - } + return u_minify(surface->texture->height0, surface->level); } -}; +%}