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;
......
...@@ -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,97 +33,144 @@ ...@@ -33,97 +33,144 @@
*/ */
%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) {
return u_minify($self->width0, level); return u_minify($self->width0, level);
} }
unsigned get_height(unsigned level=0) { unsigned get_height(unsigned level=0) {
return u_minify($self->height0, level); return u_minify($self->height0, level);
} }
unsigned get_depth(unsigned level=0) { unsigned get_depth(unsigned level=0) {
return u_minify($self->depth0, level); return u_minify($self->depth0, level);
} }
/** Get a surface which is a "view" into a texture */ /** Get a surface which is a "view" into a texture */
struct st_surface * struct st_surface *
get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0) get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0)
{ {
struct st_surface *surface; struct st_surface *surface;
if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U)) if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
SWIG_exception(SWIG_ValueError, "face out of bounds"); SWIG_exception(SWIG_ValueError, "face out of bounds");
if(level > $self->last_level) if(level > $self->last_level)
SWIG_exception(SWIG_ValueError, "level out of bounds"); SWIG_exception(SWIG_ValueError, "level out of bounds");
if(zslice >= u_minify($self->depth0, level)) if(zslice >= u_minify($self->depth0, level))
SWIG_exception(SWIG_ValueError, "zslice out of bounds"); SWIG_exception(SWIG_ValueError, "zslice out of bounds");
surface = CALLOC_STRUCT(st_surface); surface = CALLOC_STRUCT(st_surface);
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;
return surface; return surface;
fail: fail:
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;
}; };
%extend st_surface { %extend st_surface {
%immutable; %immutable;
unsigned format; unsigned format;
unsigned width; unsigned width;
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);
}
unsigned __len__(void)
{
assert(p_atomic_read(&$self->reference.count) > 0);
return $self->size;
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void read_(char **STRING, int *LENGTH)
{
struct pipe_screen *screen = $self->screen;
assert(p_atomic_read(&$self->reference.count) > 0);
*LENGTH = $self->size;
*STRING = (char *) malloc($self->size);
if(!*STRING)
return;
pipe_buffer_read(screen, $self, 0, $self->size, *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;
assert(p_atomic_read(&$self->reference.count) > 0);
if(offset > $self->size)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
if(offset + LENGTH > $self->size)
SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
pipe_buffer_write(screen, $self, offset, LENGTH, STRING);
fail:
return;
}
};
...@@ -249,7 +249,7 @@ st_context_create(struct st_device *st_dev) ...@@ -249,7 +249,7 @@ st_context_create(struct st_device *st_dev)
struct pipe_box box; struct pipe_box box;
uint32_t zero = 0; uint32_t zero = 0;
u_box_wh( 1, 1, &box ); u_box_origin_2d( 1, 1, &box );
pipe->transfer_inline_write(pipe, pipe->transfer_inline_write(pipe,
st_ctx->default_texture, st_ctx->default_texture,
......
...@@ -534,15 +534,15 @@ st_sample_surface(struct pipe_context *pipe, ...@@ -534,15 +534,15 @@ st_sample_surface(struct pipe_context *pipe,
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
void *raw; void *raw;
transfer = pipe->get_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_WRITE, PIPE_TRANSFER_WRITE,
0, 0, 0, 0,
width, width,
height); height);
if (!transfer) if (!transfer)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment