From 92a8c42baa64fbf8e1a986a0b820fe1744c1b3b3 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:19:54 +0100 Subject: python: Fix after sampler view changes. --- src/gallium/state_trackers/python/gallium.i | 1 + src/gallium/state_trackers/python/p_context.i | 33 ++++++++++++++++++++------- src/gallium/state_trackers/python/st_device.c | 32 +++++++++++++++++++------- src/gallium/state_trackers/python/st_device.h | 4 ++-- 4 files changed, 52 insertions(+), 18 deletions(-) (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index ffb084e358..632d71ccbe 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -49,6 +49,7 @@ #include "util/u_format.h" #include "util/u_dump.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" #include "tgsi/tgsi_text.h" #include "tgsi/tgsi_dump.h" diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 3f36ccb621..85c9598d06 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -169,22 +169,39 @@ struct st_context { void set_fragment_sampler_texture(unsigned index, struct pipe_texture *texture) { + struct pipe_sampler_view templ; + if(!texture) texture = $self->default_texture; - pipe_texture_reference(&$self->fragment_sampler_textures[index], texture); - $self->pipe->set_fragment_sampler_textures($self->pipe, - PIPE_MAX_SAMPLERS, - $self->fragment_sampler_textures); + pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL); + u_sampler_view_default_template(&templ, + texture, + texture->format); + $self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, + texture, + &templ); + $self->pipe->set_fragment_sampler_views($self->pipe, + PIPE_MAX_SAMPLERS, + $self->fragment_sampler_views); } void set_vertex_sampler_texture(unsigned index, struct pipe_texture *texture) { + struct pipe_sampler_view templ; + if(!texture) texture = $self->default_texture; - pipe_texture_reference(&$self->vertex_sampler_textures[index], texture); - $self->pipe->set_vertex_sampler_textures($self->pipe, - PIPE_MAX_VERTEX_SAMPLERS, - $self->vertex_sampler_textures); + pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL); + u_sampler_view_default_template(&templ, + texture, + texture->format); + $self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, + texture, + &templ); + + $self->pipe->set_vertex_sampler_views($self->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + $self->vertex_sampler_views); } void set_vertex_buffer(unsigned index, diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index a3798a5521..d5a14fd795 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -33,6 +33,7 @@ #include "cso_cache/cso_context.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "util/u_simple_shaders.h" #include "trace/tr_screen.h" #include "trace/tr_context.h" @@ -134,9 +135,9 @@ st_context_destroy(struct st_context *st_ctx) st_ctx->pipe->destroy(st_ctx->pipe); for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) - pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], NULL); + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL); for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) - pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], NULL); + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL); pipe_texture_reference(&st_ctx->default_texture, NULL); FREE(st_ctx); @@ -240,6 +241,8 @@ st_context_create(struct st_device *st_dev) struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; unsigned i; memset( &templat, 0, sizeof( templat ) ); @@ -269,14 +272,27 @@ st_context_create(struct st_device *st_dev) screen->tex_transfer_destroy(transfer); } } - + + u_sampler_view_default_template(&view_templ, + st_ctx->default_texture, + st_ctx->default_texture->format); + view = st_ctx->pipe->create_sampler_view(st_ctx->pipe, + st_ctx->default_texture, + &view_templ); + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], st_ctx->default_texture); + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view); for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) - pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], st_ctx->default_texture); - - cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->fragment_sampler_textures); - cso_set_vertex_sampler_textures(st_ctx->cso, PIPE_MAX_VERTEX_SAMPLERS, st_ctx->vertex_sampler_textures); + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view); + + st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe, + PIPE_MAX_SAMPLERS, + st_ctx->fragment_sampler_views); + st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + st_ctx->vertex_sampler_views); + + pipe_sampler_view_reference(&view, NULL); } /* vertex shader */ diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index de9e0215d8..dee9a8ca7b 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -59,8 +59,8 @@ struct st_context { void *gs; struct pipe_texture *default_texture; - struct pipe_texture *fragment_sampler_textures[PIPE_MAX_SAMPLERS]; - struct pipe_texture *vertex_sampler_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; unsigned num_vertex_buffers; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; -- cgit v1.2.3 From 3e0181f47334534be081caa912a20d278fd07149 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:21:50 +0100 Subject: python: Fix typo. --- src/gallium/state_trackers/python/p_state.i | 2 +- .../python/tests/regress/fragment-shader/frag-abs.png | Bin 0 -> 8750 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i index 5afe4d4908..eda77b56f8 100644 --- a/src/gallium/state_trackers/python/p_state.i +++ b/src/gallium/state_trackers/python/p_state.i @@ -69,7 +69,7 @@ pipe_blend_state(const char *STRING, unsigned LENGTH) { struct pipe_blend_state *state; - state = CALLOC_STRUCT(pipe_framebuffer_state); + state = CALLOC_STRUCT(pipe_blend_state); if (state) { LENGTH = MIN2(sizeof *state, LENGTH); memcpy(state, STRING, LENGTH); diff --git a/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png new file mode 100644 index 0000000000..c947a7b881 Binary files /dev/null and b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png differ -- cgit v1.2.3 From 42ab3f6fd2a019e63bf66cc59c5afb8cb6a53741 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 26 Mar 2010 17:19:45 -0700 Subject: st/python: updates for recent interface changes Still problems at runtime with vertex elements, etc. Building still disabled. --- src/gallium/state_trackers/python/p_texture.i | 86 +++++++++++----------- src/gallium/state_trackers/python/st_device.c | 22 +++--- src/gallium/state_trackers/python/st_sample.c | 5 +- .../state_trackers/python/st_softpipe_winsys.c | 2 +- 4 files changed, 58 insertions(+), 57 deletions(-) (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 761587dc53..2dd9e5050e 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -125,10 +125,10 @@ struct st_surface } %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) + void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) { struct pipe_texture *texture = $self->texture; - struct pipe_screen *screen = texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; unsigned stride; @@ -138,7 +138,7 @@ struct st_surface if(!*STRING) return; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -146,16 +146,16 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_raw(transfer, 0, 0, w, h, *STRING, stride); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); } } %cstring_input_binary(const char *STRING, unsigned LENGTH); - void put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) + void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) { struct pipe_texture *texture = $self->texture; - struct pipe_screen *screen = texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; if(stride == 0) @@ -164,7 +164,7 @@ struct st_surface if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -174,19 +174,18 @@ struct st_surface if(!transfer) SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - pipe_put_tile_raw(transfer, 0, 0, w, h, STRING, stride); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); fail: return; } - void - get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) + void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -194,17 +193,17 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); } } void - put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) + put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -212,16 +211,16 @@ struct st_surface PIPE_TRANSFER_WRITE, x, y, w, h); if(transfer) { - pipe_put_tile_rgba(transfer, 0, 0, w, h, rgba); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); } } %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); void - get_tile_rgba8(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) + get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; float *rgba; unsigned char *rgba8; @@ -244,7 +243,7 @@ struct st_surface rgba8 = (unsigned char *) *STRING; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -253,24 +252,23 @@ struct st_surface x, y, w, h); if(transfer) { - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); for(j = 0; j < h; ++j) { for(i = 0; i < w; ++i) for(k = 0; k <4; ++k) rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } free(rgba); } - void - get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) + void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -278,17 +276,16 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_z(transfer, 0, 0, w, h, z); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); } } - void - put_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) + void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -296,20 +293,21 @@ struct st_surface PIPE_TRANSFER_WRITE, x, y, w, h); if(transfer) { - pipe_put_tile_z(transfer, 0, 0, w, h, z); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); } } +/* 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) + unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; float *rgba2; const float *p1; @@ -320,7 +318,7 @@ struct st_surface if(!rgba2) return ~0; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -332,8 +330,8 @@ struct st_surface return ~0; } - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba2); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); + pipe->tex_transfer_destroy(pipe, transfer); p1 = rgba; p2 = rgba2; diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 0d87c705e7..44d65e3fc1 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -31,6 +31,7 @@ #include "pipe/p_shader_tokens.h" #include "util/u_inlines.h" #include "cso_cache/cso_context.h" +#include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_sampler.h" @@ -228,6 +229,7 @@ st_context_create(struct st_device *st_dev) /* default textures */ { + struct pipe_context *pipe = st_ctx->pipe; struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; @@ -245,21 +247,21 @@ st_context_create(struct st_device *st_dev) st_ctx->default_texture = screen->texture_create( screen, &templat ); if(st_ctx->default_texture) { - transfer = screen->get_tex_transfer(screen, - st_ctx->default_texture, - 0, 0, 0, - PIPE_TRANSFER_WRITE, - 0, 0, - st_ctx->default_texture->width0, - st_ctx->default_texture->height0); + transfer = pipe->get_tex_transfer(pipe, + st_ctx->default_texture, + 0, 0, 0, + PIPE_TRANSFER_WRITE, + 0, 0, + st_ctx->default_texture->width0, + st_ctx->default_texture->height0); if (transfer) { uint32_t *map; - map = (uint32_t *) screen->transfer_map(screen, transfer); + map = (uint32_t *) pipe->transfer_map(pipe, transfer); if(map) { *map = 0x00000000; - screen->transfer_unmap(screen, transfer); + pipe->transfer_unmap(pipe, transfer); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } } diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index e180815346..f9622533fb 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -521,7 +521,7 @@ st_sample_pixel_block(enum pipe_format format, } } - +#if 0 void st_sample_surface(struct st_surface *surface, float *rgba) { @@ -533,7 +533,7 @@ st_sample_surface(struct st_surface *surface, float *rgba) struct pipe_transfer *transfer; void *raw; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, surface->texture, surface->face, surface->level, @@ -572,3 +572,4 @@ st_sample_surface(struct st_surface *surface, float *rgba) screen->tex_transfer_destroy(transfer); } +#endif diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 985374190c..0a332aaa9f 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -30,7 +30,7 @@ #include "softpipe/sp_public.h" #include "llvmpipe/lp_public.h" #include "state_tracker/sw_winsys.h" -#include "null/null_sw_winsys.h" +#include "sw/null/null_sw_winsys.h" #include "st_winsys.h" -- cgit v1.2.3 From 588dd187c45490368354f340f5175d2c4d7cbd3c Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:52:10 +0100 Subject: Revert "python: Temporarily disable python state tracker until transfers are done by contexts" This reverts commit 50a778661930ec7aa875a9c5235e9910143ec700. --- src/gallium/state_trackers/python/SConscript | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index d0d141fd24..781f54bf2b 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -3,8 +3,7 @@ import os.path Import('*') -if 'python' in env['statetrackers'] and 0: - # FIXME: Disable python state tracker until transfers are done by contexts +if 'python' in env['statetrackers']: env = env.Clone() -- cgit v1.2.3 From 69492c3aca8361b903a7daaa697c0660faa22b04 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:21 +0100 Subject: st/python: Move surface read/write methods to context. --- src/gallium/state_trackers/python/p_context.i | 249 +++++++++++++++++++++++++- src/gallium/state_trackers/python/p_texture.i | 226 ----------------------- src/gallium/state_trackers/python/st_sample.c | 30 ++-- src/gallium/state_trackers/python/st_sample.h | 7 +- 4 files changed, 267 insertions(+), 245 deletions(-) (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index df700bc663..a8e164a072 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -362,10 +362,253 @@ error1: pipe_surface_reference(&_dst, NULL); } - void clear(unsigned buffers, const float *rgba, double depth = 0.0f, - unsigned stencil = 0) + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + unsigned stride; + + stride = util_format_get_stride(texture->format, w); + *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_input_binary(const char *STRING, unsigned LENGTH); + void + surface_write_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const char *STRING, unsigned LENGTH, unsigned stride = 0) { - $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + + if(stride == 0) + stride = util_format_get_stride(texture->format, w); + + if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) + SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(!transfer) + SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); + + pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + + fail: + return; + } + + void + surface_read_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_rgba8(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba; + unsigned char *rgba8; + unsigned i, j, k; + + *LENGTH = 0; + *STRING = NULL; + + if (!surface) + return; + + *LENGTH = h*w*4; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + rgba = malloc(h*w*4*sizeof(float)); + if(!rgba) + return; + + rgba8 = (unsigned char *) *STRING; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, + w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + for(j = 0; j < h; ++j) { + for(i = 0; i < w; ++i) + for(k = 0; k <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); + } + + free(rgba); + } + + void + surface_read_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_sample_rgba(struct st_surface *surface, + float *rgba) + { + st_sample_surface($self->pipe, surface, rgba); + } + + unsigned + surface_compare_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba, float tol = 0.0) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba2; + const float *p1; + const float *p2; + unsigned i, j, n; + + rgba2 = MALLOC(h*w*4*sizeof(float)); + if(!rgba2) + return ~0; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(!transfer) { + FREE(rgba2); + return ~0; + } + + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); + pipe->tex_transfer_destroy(pipe, transfer); + + 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; } }; diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 2dd9e5050e..923a628528 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -124,232 +124,6 @@ struct st_surface FREE($self); } - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - unsigned stride; - - stride = util_format_get_stride(texture->format, w); - *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - - if(stride == 0) - stride = util_format_get_stride(texture->format, w); - - if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(!transfer) - SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - - pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - - fail: - return; - } - - void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void - put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void - get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba; - unsigned char *rgba8; - unsigned i, j, k; - - *LENGTH = 0; - *STRING = NULL; - - if (!$self) - return; - - *LENGTH = h*w*4; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - rgba = malloc(h*w*4*sizeof(float)); - if(!rgba) - return; - - rgba8 = (unsigned char *) *STRING; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, - w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - for(j = 0; j < h; ++j) { - for(i = 0; i < w; ++i) - for(k = 0; k <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); - } - - free(rgba); - } - - void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - -/* - void - sample_rgba(float *rgba) { - st_sample_surface($self, rgba); - } -*/ - - unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba2; - const float *p1; - const float *p2; - unsigned i, j, n; - - rgba2 = MALLOC(h*w*4*sizeof(float)); - if(!rgba2) - return ~0; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(!transfer) { - FREE(rgba2); - return ~0; - } - - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); - pipe->tex_transfer_destroy(pipe, transfer); - - 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; - } }; diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index f9622533fb..e2c1e06017 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -521,12 +521,13 @@ st_sample_pixel_block(enum pipe_format format, } } -#if 0 + void -st_sample_surface(struct st_surface *surface, float *rgba) +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba) { struct pipe_texture *texture = surface->texture; - struct pipe_screen *screen = texture->screen; unsigned width = u_minify(texture->width0, surface->level); unsigned height = u_minify(texture->height0, surface->level); uint rgba_stride = width * 4; @@ -534,18 +535,18 @@ st_sample_surface(struct st_surface *surface, float *rgba) void *raw; transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - 0, 0, - width, - height); + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + 0, 0, + width, + height); if (!transfer) return; - raw = screen->transfer_map(screen, transfer); + raw = pipe->transfer_map(pipe, transfer); if (raw) { enum pipe_format format = texture->format; uint x, y; @@ -567,9 +568,8 @@ st_sample_surface(struct st_surface *surface, float *rgba) } } - screen->transfer_unmap(screen, transfer); + pipe->transfer_unmap(pipe, transfer); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } -#endif diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h index 888114d302..6fb8417add 100644 --- a/src/gallium/state_trackers/python/st_sample.h +++ b/src/gallium/state_trackers/python/st_sample.h @@ -32,6 +32,9 @@ #include "pipe/p_format.h" +struct pipe_context; +struct st_surface; + void st_sample_pixel_block(enum pipe_format format, @@ -40,7 +43,9 @@ st_sample_pixel_block(enum pipe_format format, unsigned w, unsigned h); void -st_sample_surface(struct st_surface *surface, float *rgba); +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba); #endif /* ST_SAMPLE_H_ */ -- cgit v1.2.3 From d0e7aa25a9258aaf0bf9b22c1e75eda1515a69f7 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:37 +0100 Subject: st/python: Update for util_draw_vertex_buffer changes. --- src/gallium/state_trackers/python/p_context.i | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/gallium/state_trackers/python') diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index a8e164a072..bccaeead01 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -280,8 +280,11 @@ struct st_context { struct pipe_context *pipe = $self->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_buffer *vbuf; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; + struct pipe_vertex_buffer vbuffer; float *map; unsigned size; + unsigned i; size = num_verts * num_attribs * 4 * sizeof(float); @@ -297,15 +300,44 @@ struct st_context { goto error2; memcpy(map, vertices, size); pipe_buffer_unmap(screen, vbuf); - - util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs); - + + cso_save_vertex_elements($self->cso); + + /* tell pipe about the vertex attributes */ + for (i = 0; i < num_attribs; i++) { + velements[i].src_offset = i * 4 * sizeof(float); + velements[i].instance_divisor = 0; + velements[i].vertex_buffer_index = 0; + velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + cso_set_vertex_elements($self->cso, num_attribs, velements); + + /* tell pipe about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.buffer = vbuf; + vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + vbuffer.max_index = num_verts - 1; + pipe->set_vertex_buffers(pipe, 1, &vbuffer); + + /* draw */ + pipe->draw_arrays(pipe, prim, 0, num_verts); + + cso_restore_vertex_elements($self->cso); + error2: pipe_buffer_reference(&vbuf, NULL); error1: ; } + void + clear(unsigned buffers, const float *rgba, double depth = 0.0f, + unsigned stencil = 0) + { + $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + } + void flush(unsigned flags = 0) { struct pipe_fence_handle *fence = NULL; -- cgit v1.2.3