Commit c64285ae authored by Roland Scheidegger's avatar Roland Scheidegger

python: fixes for resource changes

doesn't look quite ok yet, but sort of compiles.
parent 03d4d5a4
...@@ -72,9 +72,8 @@ ...@@ -72,9 +72,8 @@
%rename(Device) st_device; %rename(Device) st_device;
%rename(Context) st_context; %rename(Context) st_context;
%rename(Texture) pipe_texture; %rename(Resource) pipe_resource;
%rename(Surface) st_surface; %rename(Surface) st_surface;
%rename(Buffer) pipe_buffer;
%rename(BlendColor) pipe_blend_color; %rename(BlendColor) pipe_blend_color;
%rename(Blend) pipe_blend_state; %rename(Blend) pipe_blend_state;
......
...@@ -144,7 +144,7 @@ struct st_context { ...@@ -144,7 +144,7 @@ struct st_context {
} }
void set_constant_buffer(unsigned shader, unsigned index, void set_constant_buffer(unsigned shader, unsigned index,
struct pipe_buffer *buffer ) struct pipe_resource *buffer )
{ {
$self->pipe->set_constant_buffer($self->pipe, shader, index, buffer); $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
} }
...@@ -168,7 +168,7 @@ struct st_context { ...@@ -168,7 +168,7 @@ struct st_context {
} }
void set_fragment_sampler_texture(unsigned index, void set_fragment_sampler_texture(unsigned index,
struct pipe_texture *texture) { struct pipe_resource *texture) {
struct pipe_sampler_view templ; struct pipe_sampler_view templ;
if(!texture) if(!texture)
...@@ -186,7 +186,7 @@ struct st_context { ...@@ -186,7 +186,7 @@ struct st_context {
} }
void set_vertex_sampler_texture(unsigned index, void set_vertex_sampler_texture(unsigned index,
struct pipe_texture *texture) { struct pipe_resource *texture) {
struct pipe_sampler_view templ; struct pipe_sampler_view templ;
if(!texture) if(!texture)
...@@ -208,7 +208,7 @@ struct st_context { ...@@ -208,7 +208,7 @@ struct st_context {
unsigned stride, unsigned stride,
unsigned max_index, unsigned max_index,
unsigned buffer_offset, unsigned buffer_offset,
struct pipe_buffer *buffer) struct pipe_resource *buffer)
{ {
unsigned i; unsigned i;
struct pipe_vertex_buffer state; struct pipe_vertex_buffer state;
...@@ -252,7 +252,7 @@ struct st_context { ...@@ -252,7 +252,7 @@ struct st_context {
$self->pipe->draw_arrays($self->pipe, mode, start, count); $self->pipe->draw_arrays($self->pipe, mode, start, count);
} }
void draw_elements( struct pipe_buffer *indexBuffer, void draw_elements( struct pipe_resource *indexBuffer,
unsigned indexSize, unsigned indexSize,
unsigned mode, unsigned start, unsigned count) unsigned mode, unsigned start, unsigned count)
{ {
...@@ -262,7 +262,7 @@ struct st_context { ...@@ -262,7 +262,7 @@ struct st_context {
mode, start, count); mode, start, count);
} }
void draw_range_elements( struct pipe_buffer *indexBuffer, void draw_range_elements( struct pipe_resource *indexBuffer,
unsigned indexSize, unsigned minIndex, unsigned maxIndex, unsigned indexSize, unsigned minIndex, unsigned maxIndex,
unsigned mode, unsigned start, unsigned count) unsigned mode, unsigned start, unsigned count)
{ {
...@@ -279,7 +279,8 @@ struct st_context { ...@@ -279,7 +279,8 @@ struct st_context {
{ {
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_screen *screen = pipe->screen; struct pipe_screen *screen = pipe->screen;
struct pipe_buffer *vbuf; struct pipe_resource *vbuf;
struct pipe_transfer *transfer;
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
struct pipe_vertex_buffer vbuffer; struct pipe_vertex_buffer vbuffer;
float *map; float *map;
...@@ -294,11 +295,11 @@ struct st_context { ...@@ -294,11 +295,11 @@ struct st_context {
if(!vbuf) if(!vbuf)
goto error1; goto error1;
map = pipe_buffer_map(screen, vbuf, PIPE_TRANSFER_WRITE); map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
if (!map) if (!map)
goto error2; goto error2;
memcpy(map, vertices, size); memcpy(map, vertices, size);
pipe_buffer_unmap(screen, vbuf); pipe_buffer_unmap(pipe, vbuf, transfer);
cso_save_vertex_elements($self->cso); cso_save_vertex_elements($self->cso);
...@@ -325,7 +326,7 @@ struct st_context { ...@@ -325,7 +326,7 @@ struct st_context {
cso_restore_vertex_elements($self->cso); cso_restore_vertex_elements($self->cso);
error2: error2:
pipe_buffer_reference(&vbuf, NULL); pipe_resource_reference(&vbuf, NULL);
error1: error1:
; ;
} }
...@@ -399,7 +400,7 @@ error1: ...@@ -399,7 +400,7 @@ error1:
unsigned x, unsigned y, unsigned w, unsigned h, unsigned x, unsigned y, unsigned w, unsigned h,
char **STRING, int *LENGTH) char **STRING, int *LENGTH)
{ {
struct pipe_texture *texture = surface->texture; struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
unsigned stride; unsigned stride;
...@@ -410,7 +411,7 @@ error1: ...@@ -410,7 +411,7 @@ error1:
if(!*STRING) if(!*STRING)
return; return;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -419,7 +420,7 @@ error1: ...@@ -419,7 +420,7 @@ error1:
x, y, w, h); x, y, w, h);
if(transfer) { if(transfer) {
pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
} }
...@@ -429,7 +430,7 @@ error1: ...@@ -429,7 +430,7 @@ error1:
unsigned x, unsigned y, unsigned w, unsigned h, unsigned x, unsigned y, unsigned w, unsigned h,
const char *STRING, unsigned LENGTH, unsigned stride = 0) const char *STRING, unsigned LENGTH, unsigned stride = 0)
{ {
struct pipe_texture *texture = surface->texture; struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
...@@ -439,7 +440,7 @@ error1: ...@@ -439,7 +440,7 @@ error1:
if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -450,7 +451,7 @@ error1: ...@@ -450,7 +451,7 @@ error1:
SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
fail: fail:
return; return;
...@@ -463,7 +464,7 @@ error1: ...@@ -463,7 +464,7 @@ error1:
{ {
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -472,7 +473,7 @@ error1: ...@@ -472,7 +473,7 @@ error1:
x, y, w, h); x, y, w, h);
if(transfer) { if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
} }
...@@ -483,7 +484,7 @@ error1: ...@@ -483,7 +484,7 @@ error1:
{ {
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -492,7 +493,7 @@ error1: ...@@ -492,7 +493,7 @@ error1:
x, y, w, h); x, y, w, h);
if(transfer) { if(transfer) {
pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
} }
...@@ -525,14 +526,13 @@ error1: ...@@ -525,14 +526,13 @@ error1:
rgba8 = (unsigned char *) *STRING; rgba8 = (unsigned char *) *STRING;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
surface->zslice, surface->zslice,
PIPE_TRANSFER_READ, PIPE_TRANSFER_READ,
x, y, x, y, w, h);
w, h);
if(transfer) { if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
for(j = 0; j < h; ++j) { for(j = 0; j < h; ++j) {
...@@ -540,7 +540,7 @@ error1: ...@@ -540,7 +540,7 @@ error1:
for(k = 0; k <4; ++k) for(k = 0; k <4; ++k)
rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
} }
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
free(rgba); free(rgba);
...@@ -553,7 +553,7 @@ error1: ...@@ -553,7 +553,7 @@ error1:
{ {
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -562,7 +562,7 @@ error1: ...@@ -562,7 +562,7 @@ error1:
x, y, w, h); x, y, w, h);
if(transfer) { if(transfer) {
pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
} }
...@@ -573,7 +573,7 @@ error1: ...@@ -573,7 +573,7 @@ error1:
{ {
struct pipe_context *pipe = $self->pipe; struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -582,7 +582,7 @@ error1: ...@@ -582,7 +582,7 @@ error1:
x, y, w, h); x, y, w, h);
if(transfer) { if(transfer) {
pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
} }
} }
...@@ -609,7 +609,7 @@ error1: ...@@ -609,7 +609,7 @@ error1:
if(!rgba2) if(!rgba2)
return ~0; return ~0;
transfer = pipe->get_tex_transfer(pipe, transfer = pipe_get_transfer(pipe,
surface->texture, surface->texture,
surface->face, surface->face,
surface->level, surface->level,
...@@ -622,7 +622,7 @@ error1: ...@@ -622,7 +622,7 @@ error1:
} }
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
pipe->tex_transfer_destroy(pipe, transfer); pipe->transfer_destroy(pipe, transfer);
p1 = rgba; p1 = rgba;
p2 = rgba2; p2 = rgba2;
......
...@@ -81,7 +81,7 @@ struct st_device { ...@@ -81,7 +81,7 @@ struct st_device {
/** /**
* Check if the given pipe_format is supported as a texture or * Check if the given pipe_format is supported as a texture or
* drawing surface. * drawing surface.
* \param type one of PIPE_TEXTURE, PIPE_SURFACE * \param tex_usage bitmask of PIPE_BIND flags
*/ */
int is_format_supported( enum pipe_format format, int is_format_supported( enum pipe_format format,
enum pipe_texture_target target, enum pipe_texture_target target,
...@@ -103,7 +103,7 @@ struct st_device { ...@@ -103,7 +103,7 @@ struct st_device {
return st_context_create($self); return st_context_create($self);
} }
struct pipe_texture * struct pipe_resource *
texture_create( texture_create(
enum pipe_format format, enum pipe_format format,
unsigned width, unsigned width,
...@@ -113,7 +113,7 @@ struct st_device { ...@@ -113,7 +113,7 @@ struct st_device {
enum pipe_texture_target target = PIPE_TEXTURE_2D, enum pipe_texture_target target = PIPE_TEXTURE_2D,
unsigned tex_usage = 0 unsigned tex_usage = 0
) { ) {
struct pipe_texture templat; struct pipe_resource templat;
/* We can't really display surfaces with the python statetracker so mask /* We can't really display surfaces with the python statetracker so mask
* out that usage */ * out that usage */
...@@ -128,12 +128,12 @@ struct st_device { ...@@ -128,12 +128,12 @@ struct st_device {
templat.target = target; templat.target = target;
templat.bind = tex_usage; templat.bind = tex_usage;
return $self->screen->texture_create($self->screen, &templat); return $self->screen->resource_create($self->screen, &templat);
} }
struct pipe_buffer * struct pipe_resource *
buffer_create(unsigned size, unsigned alignment = 0, unsigned usage = 0) { buffer_create(unsigned size, unsigned bind = 0) {
return pipe_buffer_create($self->screen, alignment, usage, size); return pipe_buffer_create($self->screen, bind, size);
} }
}; };
...@@ -33,29 +33,30 @@ ...@@ -33,29 +33,30 @@
*/ */
%nodefaultctor pipe_texture; %nodefaultctor pipe_resource;
%nodefaultctor st_surface; %nodefaultctor st_surface;
%nodefaultctor pipe_buffer;
%nodefaultdtor pipe_texture; %nodefaultdtor pipe_resource;
%nodefaultdtor st_surface; %nodefaultdtor st_surface;
%nodefaultdtor pipe_buffer;
%ignore pipe_texture::screen; %ignore pipe_resource::screen;
%immutable st_surface::texture; %immutable st_surface::texture;
%immutable st_surface::face; %immutable st_surface::face;
%immutable st_surface::level; %immutable st_surface::level;
%immutable st_surface::zslice; %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 { %extend pipe_resource {
~pipe_texture() { ~pipe_resource() {
struct pipe_texture *ptr = $self; struct pipe_resource *ptr = $self;
pipe_texture_reference(&ptr, NULL); pipe_resource_reference(&ptr, NULL);
} }
unsigned get_width(unsigned level=0) { unsigned get_width(unsigned level=0) {
...@@ -87,7 +88,7 @@ ...@@ -87,7 +88,7 @@
if(!surface) if(!surface)
return NULL; return NULL;
pipe_texture_reference(&surface->texture, $self); pipe_resource_reference(&surface->texture, $self);
surface->face = face; surface->face = face;
surface->level = level; surface->level = level;
surface->zslice = zslice; surface->zslice = zslice;
...@@ -98,13 +99,59 @@ ...@@ -98,13 +99,59 @@
return NULL; return NULL;
} }
unsigned __len__(void)
{
assert($self->target == PIPE_BUFFER);
assert(p_atomic_read(&$self->reference.count) > 0);
return $self->width0;
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void read_(char **STRING, int *LENGTH)
{
struct pipe_screen *screen = $self->screen;
/* XXX need context here not screen */
assert($self->target == PIPE_BUFFER);
assert(p_atomic_read(&$self->reference.count) > 0);
*LENGTH = $self->width0;
*STRING = (char *) malloc($self->width0);
if(!*STRING)
return;
pipe_buffer_read(screen, $self, 0, $self->width0, *STRING);
}
%cstring_input_binary(const char *STRING, unsigned LENGTH);
void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0)
{
struct pipe_screen *screen = $self->screen;
/* XXX need context here not screen */
assert($self->target == PIPE_BUFFER);
assert(p_atomic_read(&$self->reference.count) > 0);
if(offset > $self->width0)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
if(offset + LENGTH > $self->width0)
SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
pipe_buffer_write(screen, $self, offset, LENGTH, STRING);
fail:
return;
}
}; };
struct st_surface struct st_surface
{ {
%immutable; %immutable;
struct pipe_texture *texture; struct pipe_resource *texture;
unsigned face; unsigned face;
unsigned level; unsigned level;
unsigned zslice; unsigned zslice;
...@@ -120,7 +167,7 @@ struct st_surface ...@@ -120,7 +167,7 @@ struct st_surface
unsigned height; unsigned height;
~st_surface() { ~st_surface() {
pipe_texture_reference(&$self->texture, NULL); pipe_resource_reference(&$self->texture, NULL);
FREE($self); FREE($self);
} }
...@@ -146,55 +193,3 @@ struct st_surface ...@@ -146,55 +193,3 @@ struct st_surface
return u_minify(surface->texture->height0, surface->level); return u_minify(surface->texture->height0, surface->level);
} }
%} %}
/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
%rename(read) read_;
%rename(write) write_;
%extend pipe_buffer {
~pipe_buffer() {
struct pipe_buffer *ptr = $self;
pipe_buffer_reference(&ptr, NULL);
}