From e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 19 Mar 2010 16:29:22 +0100 Subject: [PATCH] st/vega: fix up vega state tracker to use cso changes use cso fragment sampler views instead of sampler textures. since we don't really change views, try to store sampler views instead of the textures to avoid having to recreate views most of the time. --- src/gallium/state_trackers/vega/api_filters.c | 73 ++++++++++++------- src/gallium/state_trackers/vega/image.c | 37 ++++++---- src/gallium/state_trackers/vega/image.h | 4 +- src/gallium/state_trackers/vega/mask.c | 66 ++++++++++------- src/gallium/state_trackers/vega/mask.h | 2 +- src/gallium/state_trackers/vega/paint.c | 62 +++++++++++----- src/gallium/state_trackers/vega/paint.h | 2 +- src/gallium/state_trackers/vega/renderer.c | 37 ++++++---- src/gallium/state_trackers/vega/renderer.h | 3 +- src/gallium/state_trackers/vega/shader.c | 34 ++++----- src/gallium/state_trackers/vega/vg_context.c | 16 +++- src/gallium/state_trackers/vega/vg_context.h | 5 +- src/gallium/state_trackers/vega/vg_tracker.c | 58 ++++++++++----- 13 files changed, 253 insertions(+), 146 deletions(-) diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c index 18e2cc1f250..a643f38624f 100644 --- a/src/gallium/state_trackers/vega/api_filters.c +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -40,6 +40,7 @@ #include "util/u_format.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "asm_filters.h" @@ -53,7 +54,7 @@ struct filter_info { const void *const_buffer; VGint const_buffer_len; VGTilingMode tiling_mode; - struct pipe_texture *extra_texture; + struct pipe_sampler_view *extra_texture_view; }; static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, @@ -91,13 +92,35 @@ static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, return tex; } +static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context *ctx, + const VGuint *color_data, + const VGint color_data_len) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture_1d(ctx, color_data, color_data_len); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + static INLINE struct pipe_surface * setup_framebuffer(struct vg_image *dst) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_framebuffer_state fb; struct pipe_surface *dst_surf = pipe->screen->get_tex_surface( - pipe->screen, dst->texture, 0, 0, 0, + pipe->screen, dst->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* drawing dest */ @@ -168,7 +191,7 @@ static void setup_constant_buffer(struct vg_context *ctx, const void *buffer, static void setup_samplers(struct vg_context *ctx, struct filter_info *info) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state sampler[3]; int num_samplers = 0; int num_textures = 0; @@ -177,10 +200,10 @@ static void setup_samplers(struct vg_context *ctx, struct filter_info *info) samplers[1] = NULL; samplers[2] = NULL; samplers[3] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; - textures[3] = NULL; + sampler_views[0] = NULL; + sampler_views[1] = NULL; + sampler_views[2] = NULL; + sampler_views[3] = NULL; memset(&sampler[0], 0, sizeof(struct pipe_sampler_state)); sampler[0].wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -215,21 +238,21 @@ static void setup_samplers(struct vg_context *ctx, struct filter_info *info) } samplers[0] = &sampler[0]; - textures[0] = info->src->texture; + sampler_views[0] = info->src->sampler_view; ++num_samplers; ++num_textures; - if (info->extra_texture) { + if (info->extra_texture_view) { memcpy(&sampler[1], &sampler[0], sizeof(struct pipe_sampler_state)); samplers[1] = &sampler[1]; - textures[1] = info->extra_texture; + sampler_views[1] = info->extra_texture_view; ++num_samplers; ++num_textures; } cso_set_samplers(ctx->cso_context, num_samplers, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, num_textures, textures); + cso_set_fragment_sampler_views(ctx->cso_context, num_textures, sampler_views); } static struct vg_shader * setup_color_matrix(struct vg_context *ctx, void *user_data) @@ -308,7 +331,7 @@ static void execute_filter(struct vg_context *ctx, cso_save_viewport(ctx->cso_context); cso_save_blend(ctx->cso_context); cso_save_samplers(ctx->cso_context); - cso_save_sampler_textures(ctx->cso_context); + cso_save_fragment_sampler_views(ctx->cso_context); dst_surf = setup_framebuffer(info->dst); setup_viewport(info->dst); @@ -318,7 +341,7 @@ static void execute_filter(struct vg_context *ctx, setup_samplers(ctx, info); renderer_draw_texture(ctx->renderer, - info->src->texture, + info->src->sampler_view->texture, info->dst->x, info->dst->y, info->dst->x + info->dst->width, info->dst->y + info->dst->height, @@ -331,7 +354,7 @@ static void execute_filter(struct vg_context *ctx, cso_restore_viewport(ctx->cso_context); cso_restore_blend(ctx->cso_context); cso_restore_samplers(ctx->cso_context); - cso_restore_sampler_textures(ctx->cso_context); + cso_restore_fragment_sampler_views(ctx->cso_context); vg_shader_destroy(ctx, shader); @@ -369,7 +392,7 @@ void vgColorMatrix(VGImage dst, VGImage src, info.const_buffer = matrix; info.const_buffer_len = 20 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); } @@ -479,7 +502,7 @@ void vgConvolve(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = buffer_len * sizeof(VGfloat); info.tiling_mode = tilingMode; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); free(buffer); @@ -669,7 +692,7 @@ void vgGaussianBlur(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = buffer_len * sizeof(VGfloat); info.tiling_mode = tilingMode; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); free(buffer); @@ -688,7 +711,7 @@ void vgLookup(VGImage dst, VGImage src, struct vg_image *d, *s; VGuint color_data[256]; VGint i; - struct pipe_texture *lut_texture; + struct pipe_sampler_view *lut_texture_view; VGfloat buffer[4]; struct filter_info info; @@ -714,7 +737,7 @@ void vgLookup(VGImage dst, VGImage src, color_data[i] = blueLUT[i] << 24 | greenLUT[i] << 16 | redLUT[i] << 8 | alphaLUT[i]; } - lut_texture = create_texture_1d(ctx, color_data, 255); + lut_texture_view = create_texture_1d_view(ctx, color_data, 255); buffer[0] = 0.f; buffer[1] = 0.f; @@ -728,11 +751,11 @@ void vgLookup(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = 4 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = lut_texture; + info.extra_texture_view = lut_texture_view; execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_sampler_view_reference(&lut_texture_view, NULL); } void vgLookupSingle(VGImage dst, VGImage src, @@ -743,7 +766,7 @@ void vgLookupSingle(VGImage dst, VGImage src, { struct vg_context *ctx = vg_current_context(); struct vg_image *d, *s; - struct pipe_texture *lut_texture; + struct pipe_sampler_view *lut_texture_view; VGfloat buffer[4]; struct filter_info info; VGuint color_data[256]; @@ -783,7 +806,7 @@ void vgLookupSingle(VGImage dst, VGImage src, color_data[i] = blue << 24 | green << 16 | red << 8 | alpha; } - lut_texture = create_texture_1d(ctx, color_data, 256); + lut_texture_view = create_texture_1d_view(ctx, color_data, 256); buffer[0] = 0.f; buffer[1] = 0.f; @@ -797,9 +820,9 @@ void vgLookupSingle(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = 4 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = lut_texture; + info.extra_texture_view = lut_texture_view; execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_sampler_view_reference(&lut_texture_view, NULL); } diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c index a71579cd264..c3268a84a60 100644 --- a/src/gallium/state_trackers/vega/image.c +++ b/src/gallium/state_trackers/vega/image.c @@ -43,6 +43,7 @@ #include "util/u_tile.h" #include "util/u_memory.h" #include "util/u_math.h" +#include "util/u_sampler.h" static enum pipe_format vg_format_to_pipe(VGImageFormat format) { @@ -81,7 +82,7 @@ static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) static void vg_copy_texture(struct vg_context *ctx, struct pipe_texture *dst, VGint dx, VGint dy, - struct pipe_texture *src, VGint sx, VGint sy, + struct pipe_sampler_view *src, VGint sx, VGint sy, VGint width, VGint height) { VGfloat dst_loc[4], src_loc[4]; @@ -103,8 +104,8 @@ static void vg_copy_texture(struct vg_context *ctx, src_loc[3] = height; src_bounds[0] = 0.f; src_bounds[1] = 0.f; - src_bounds[2] = src->width0; - src_bounds[3] = src->height0; + src_bounds[2] = src->texture->width0; + src_bounds[3] = src->texture->height0; vg_bound_rect(src_loc, src_bounds, src_shift); vg_bound_rect(dst_loc, dst_bounds, dst_shift); @@ -218,7 +219,7 @@ void vg_copy_surface(struct vg_context *ctx, static struct pipe_texture *image_texture(struct vg_image *img) { - struct pipe_texture *tex = img->texture; + struct pipe_texture *tex = img->sampler_view->texture; return tex; } @@ -247,9 +248,12 @@ struct vg_image * image_create(VGImageFormat format, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); struct pipe_texture pt, *newtex; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); @@ -281,7 +285,12 @@ struct vg_image * image_create(VGImageFormat format, debug_assert(newtex); - image->texture = newtex; + u_sampler_view_default_template(&view_templ, newtex, newtex->format); + view = pipe->create_sampler_view(pipe, newtex, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&newtex, NULL); + + image->sampler_view = view; vg_context_add_object(ctx, VG_OBJECT_IMAGE, image); @@ -345,7 +354,7 @@ void image_destroy(struct vg_image *img) array_destroy(img->children_array); } - pipe_texture_reference(&img->texture, NULL); + pipe_sampler_view_reference(&img->sampler_view, NULL); free(img); } @@ -444,7 +453,7 @@ void image_get_sub_data(struct vg_image * image, { struct pipe_transfer *transfer = pipe->get_tex_transfer(pipe, - image->texture, 0, 0, 0, + image->sampler_view->texture, 0, 0, 0, PIPE_TRANSFER_READ, 0, 0, image->x + image->width, @@ -478,9 +487,9 @@ struct vg_image * image_child_image(struct vg_image *parent, image->width = width; image->height = height; image->parent = parent; - image->texture = 0; - pipe_texture_reference(&image->texture, - parent->texture); + image->sampler_view = NULL; + pipe_sampler_view_reference(&image->sampler_view, + parent->sampler_view); image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -514,8 +523,8 @@ void image_copy(struct vg_image *dst, VGint dx, VGint dy, } /* make sure rendering has completed */ ctx->pipe->flush(ctx->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - vg_copy_texture(ctx, dst->texture, dst->x + dx, dst->y + dy, - src->texture, src->x + sx, src->y + sy, width, height); + vg_copy_texture(ctx, dst->sampler_view->texture, dst->x + dx, dst->y + dy, + src->sampler_view, src->x + sx, src->y + sy, width, height); } void image_draw(struct vg_image *img) @@ -624,12 +633,12 @@ VGboolean vg_image_overlaps(struct vg_image *dst, } VGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { img->sampler.min_img_filter = image_sampler_filter(img->base.ctx); img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx); samplers[3] = &img->sampler; - textures[3] = img->texture; + sampler_views[3] = img->sampler_view; return 1; } diff --git a/src/gallium/state_trackers/vega/image.h b/src/gallium/state_trackers/vega/image.h index 78e17cffa64..805b35fab9f 100644 --- a/src/gallium/state_trackers/vega/image.h +++ b/src/gallium/state_trackers/vega/image.h @@ -43,7 +43,7 @@ struct vg_image { struct vg_image *parent; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; struct pipe_sampler_state sampler; struct array *children_array; @@ -89,7 +89,7 @@ void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, VGint width, VGint height); VGint image_bind_samplers(struct vg_image *dst, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); VGboolean vg_image_overlaps(struct vg_image *dst, struct vg_image *src); diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c index 839dc19a3b8..316ea7a9c95 100644 --- a/src/gallium/state_trackers/vega/mask.c +++ b/src/gallium/state_trackers/vega/mask.c @@ -45,7 +45,7 @@ struct vg_mask_layer { VGint width; VGint height; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; }; static INLINE struct pipe_surface * @@ -54,7 +54,7 @@ alpha_mask_surface(struct vg_context *ctx, int usage) struct pipe_screen *screen = ctx->pipe->screen; struct st_framebuffer *stfb = ctx->draw_buffer; return screen->get_tex_surface(screen, - stfb->alpha_mask, + stfb->alpha_mask_view->texture, 0, 0, 0, usage); } @@ -284,35 +284,33 @@ static void setup_mask_operation(VGMaskOperation operation) cso_set_fragment_shader_handle(ctx->cso_context, shader); } -static void setup_mask_samplers(struct pipe_texture *umask) +static void setup_mask_samplers(struct pipe_sampler_view *umask) { struct vg_context *ctx = vg_current_context(); struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct st_framebuffer *fb_buffers = ctx->draw_buffer; - struct pipe_texture *uprev = NULL; + struct pipe_sampler_view *uprev = NULL; struct pipe_sampler_state sampler; - uprev = fb_buffers->blend_texture; + uprev = fb_buffers->blend_texture_view; sampler = ctx->mask.sampler; sampler.normalized_coords = 1; samplers[0] = NULL; samplers[1] = NULL; - samplers[2] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; + sampler_views[0] = NULL; + sampler_views[1] = NULL; samplers[0] = &sampler; samplers[1] = &ctx->mask.sampler; - textures[0] = umask; - textures[1] = uprev; + sampler_views[0] = umask; + sampler_views[1] = uprev; cso_set_samplers(ctx->cso_context, 2, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, 2, textures); + cso_set_fragment_sampler_views(ctx->cso_context, 2, sampler_views); } @@ -411,12 +409,13 @@ static void surface_fill(struct pipe_surface *surf, } -static void mask_using_texture(struct pipe_texture *texture, +static void mask_using_texture(struct pipe_sampler_view *sampler_view, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); + struct pipe_texture *texture = sampler_view->texture; struct pipe_surface *surface = alpha_mask_surface(ctx, PIPE_BUFFER_USAGE_GPU_WRITE); VGint offsets[4], loc[4]; @@ -439,13 +438,13 @@ static void mask_using_texture(struct pipe_texture *texture, vg_prepare_blend_surface_from_mask(ctx); cso_save_samplers(ctx->cso_context); - cso_save_sampler_textures(ctx->cso_context); + cso_save_fragment_sampler_views(ctx->cso_context); cso_save_framebuffer(ctx->cso_context); cso_save_blend(ctx->cso_context); cso_save_fragment_shader(ctx->cso_context); cso_save_viewport(ctx->cso_context); - setup_mask_samplers(texture); + setup_mask_samplers(sampler_view); setup_mask_blend(); setup_mask_operation(operation); setup_mask_framebuffer(surface, surface->width, surface->height); @@ -463,7 +462,7 @@ static void mask_using_texture(struct pipe_texture *texture, cso_restore_framebuffer(ctx->cso_context); cso_restore_fragment_shader(ctx->cso_context); cso_restore_samplers(ctx->cso_context); - cso_restore_sampler_textures(ctx->cso_context); + cso_restore_fragment_sampler_views(ctx->cso_context); cso_restore_viewport(ctx->cso_context); pipe_surface_reference(&surface, NULL); @@ -484,7 +483,11 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) { struct pipe_texture pt; + struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = ctx->pipe->screen; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view = NULL; + struct pipe_texture *texture; memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; @@ -496,7 +499,14 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; pt.compressed = 0; - mask->texture = screen->texture_create(screen, &pt); + texture = screen->texture_create(screen, &pt); + + if (texture) { + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + } + pipe_texture_reference(&texture, NULL); + mask->sampler_view = view; } vg_context_add_object(ctx, VG_OBJECT_MASK, mask); @@ -525,7 +535,7 @@ void mask_layer_fill(struct vg_mask_layer *layer, alpha_color[3] = value; surface = ctx->pipe->screen->get_tex_surface( - ctx->pipe->screen, layer->texture, + ctx->pipe->screen, layer->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -545,10 +555,10 @@ void mask_copy(struct vg_mask_layer *layer, struct st_framebuffer *fb_buffers = ctx->draw_buffer; renderer_copy_texture(ctx->renderer, - layer->texture, + layer->sampler_view, sx, sy, sx + width, sy + height, - fb_buffers->alpha_mask, + fb_buffers->alpha_mask_view->texture, dx, dy, dx + width, dy + height); } @@ -562,7 +572,7 @@ static void mask_layer_render_to(struct vg_mask_layer *layer, struct pipe_screen *screen = ctx->pipe->screen; struct pipe_surface *surface; - surface = screen->get_tex_surface(screen, layer->texture, 0, 0, 0, + surface = screen->get_tex_surface(screen, layer->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); cso_save_framebuffer(ctx->cso_context); @@ -604,8 +614,8 @@ void mask_render_to(struct path *path, struct vg_mask_layer *temp_layer; VGint width, height; - width = fb_buffers->alpha_mask->width0; - height = fb_buffers->alpha_mask->width0; + width = fb_buffers->alpha_mask_view->texture->width0; + height = fb_buffers->alpha_mask_view->texture->width0; temp_layer = mask_layer_create(width, height); @@ -622,7 +632,7 @@ void mask_using_layer(struct vg_mask_layer *layer, VGint x, VGint y, VGint width, VGint height) { - mask_using_texture(layer->texture, operation, + mask_using_texture(layer->sampler_view, operation, x, y, width, height); } @@ -644,7 +654,7 @@ void mask_using_image(struct vg_image *image, VGint x, VGint y, VGint width, VGint height) { - mask_using_texture(image->texture, operation, + mask_using_texture(image->sampler_view, operation, x, y, width, height); } @@ -672,7 +682,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height, } VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { struct vg_context *ctx = vg_current_context(); @@ -680,7 +690,7 @@ VGint mask_bind_samplers(struct pipe_sampler_state **samplers, struct st_framebuffer *fb_buffers = ctx->draw_buffer; samplers[1] = &ctx->mask.sampler; - textures[1] = fb_buffers->alpha_mask; + sampler_views[1] = fb_buffers->alpha_mask_view; return 1; } else return 0; diff --git a/src/gallium/state_trackers/vega/mask.h b/src/gallium/state_trackers/vega/mask.h index 5eaaede0e3a..4feacbefda8 100644 --- a/src/gallium/state_trackers/vega/mask.h +++ b/src/gallium/state_trackers/vega/mask.h @@ -63,6 +63,6 @@ void mask_fill(VGint x, VGint y, VGfloat value); VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); #endif diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c index dc56b8c5f3b..508e1863a57 100644 --- a/src/gallium/state_trackers/vega/paint.c +++ b/src/gallium/state_trackers/vega/paint.c @@ -37,6 +37,7 @@ #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_math.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" @@ -61,7 +62,7 @@ struct vg_paint { VGfloat vals[5]; VGint valsi[5]; } radial; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; struct pipe_sampler_state sampler; VGfloat *ramp_stops; @@ -72,7 +73,7 @@ struct vg_paint { } gradient; struct { - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; VGTilingMode tiling_mode; struct pipe_sampler_state sampler; } pattern; @@ -173,6 +174,26 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) return tex; } +static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_paint *p) +{ + struct pipe_context *pipe = p->base.ctx->pipe; + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_gradient_texture(p); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + struct vg_paint * paint_create(struct vg_context *ctx) { struct vg_paint *paint = CALLOC_STRUCT(vg_paint); @@ -207,8 +228,9 @@ struct vg_paint * paint_create(struct vg_context *ctx) void paint_destroy(struct vg_paint *paint) { struct vg_context *ctx = paint->base.ctx; - if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); if (ctx) vg_context_remove_object(ctx, VG_OBJECT_PAINT, paint); @@ -329,8 +351,8 @@ static INLINE void paint_pattern_buffer(struct vg_paint *paint, void *buffer) map[4] = 0.f; map[5] = 1.f; - map[6] = paint->pattern.texture->width0; - map[7] = paint->pattern.texture->height0; + map[6] = paint->pattern.sampler_view->texture->width0; + map[7] = paint->pattern.sampler_view->texture->height0; { struct matrix mat; memcpy(&mat, &ctx->state.vg.fill_paint_to_user_matrix, @@ -394,12 +416,12 @@ void paint_set_ramp_stops(struct vg_paint *paint, const VGfloat *stops, create_gradient_data(stops, num / 5, paint->gradient.color_data, 1024); - if (paint->gradient.texture) { - pipe_texture_reference(&paint->gradient.texture, NULL); - paint->gradient.texture = 0; + if (paint->gradient.sampler_view) { + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + paint->gradient.sampler_view = NULL; } - paint->gradient.texture = create_gradient_texture(paint); + paint->gradient.sampler_view = create_gradient_sampler_view(paint); } void paint_set_colori(struct vg_paint *p, @@ -459,12 +481,12 @@ void paint_set_radial_gradient(struct vg_paint *paint, void paint_set_pattern(struct vg_paint *paint, struct vg_image *img) { - if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); - paint->pattern.texture = 0; - pipe_texture_reference(&paint->pattern.texture, - img->texture); + paint->pattern.sampler_view = NULL; + pipe_sampler_view_reference(&paint->pattern.sampler_view, + img->sampler_view); } void paint_set_pattern_tiling(struct vg_paint *paint, @@ -611,18 +633,18 @@ VGTilingMode paint_pattern_tiling(struct vg_paint *paint) } VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { struct vg_context *ctx = vg_current_context(); switch(paint->type) { case VG_PAINT_TYPE_LINEAR_GRADIENT: case VG_PAINT_TYPE_RADIAL_GRADIENT: { - if (paint->gradient.texture) { + if (paint->gradient.sampler_view) { paint->gradient.sampler.min_img_filter = image_sampler_filter(ctx); paint->gradient.sampler.mag_img_filter = image_sampler_filter(ctx); samplers[0] = &paint->gradient.sampler; - textures[0] = paint->gradient.texture; + sampler_views[0] = paint->gradient.sampler_view; return 1; } } @@ -634,7 +656,7 @@ VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **sa paint->pattern.sampler.min_img_filter = image_sampler_filter(ctx); paint->pattern.sampler.mag_img_filter = image_sampler_filter(ctx); samplers[0] = &paint->pattern.sampler; - textures[0] = paint->pattern.texture; + sampler_views[0] = paint->pattern.sampler_view; return 1; } break; @@ -647,7 +669,7 @@ VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **sa void paint_resolve_type(struct vg_paint *paint) { if (paint->type == VG_PAINT_TYPE_PATTERN && - !paint->pattern.texture) { + !paint->pattern.sampler_view) { paint->type = VG_PAINT_TYPE_COLOR; } } diff --git a/src/gallium/state_trackers/vega/paint.h b/src/gallium/state_trackers/vega/paint.h index 999b5c167ca..9ea67c4b1e6 100644 --- a/src/gallium/state_trackers/vega/paint.h +++ b/src/gallium/state_trackers/vega/paint.h @@ -108,7 +108,7 @@ VGboolean paint_color_ramp_premultiplied(struct vg_paint *paint); VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); VGint paint_constant_buffer_size(struct vg_paint *paint); void paint_fill_constant_buffer(struct vg_paint *paint, diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 47e8b470a11..2bb4c8bc756 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -39,6 +39,7 @@ #include "util/u_simple_shaders.h" #include "util/u_memory.h" #include "util/u_rect.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" @@ -263,7 +264,7 @@ void renderer_draw_texture(struct renderer *r, } void renderer_copy_texture(struct renderer *ctx, - struct pipe_texture *src, + struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, struct pipe_texture *dst, @@ -272,6 +273,7 @@ void renderer_copy_texture(struct renderer *ctx, { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; + struct pipe_texture *tex = src->texture; struct pipe_buffer *buf; struct pipe_surface *dst_surf = screen->get_tex_surface( screen, dst, 0, 0, 0, @@ -279,8 +281,8 @@ void renderer_copy_texture(struct renderer *ctx, struct pipe_framebuffer_state fb; float s0, t0, s1, t1; - assert(src->width0 != 0); - assert(src->height0 != 0); + assert(tex->width0 != 0); + assert(tex->height0 != 0); assert(dst->width0 != 0); assert(dst->height0 != 0); @@ -290,10 +292,10 @@ void renderer_copy_texture(struct renderer *ctx, #endif #if 1 - s0 = sx1 / src->width0; - s1 = sx2 / src->width0; - t0 = sy1 / src->height0; - t1 = sy2 / src->height0; + s0 = sx1 / tex->width0; + s1 = sx2 / tex->width0; + t0 = sy1 / tex->height0; + t1 = sy2 / tex->height0; #else s0 = 0; s1 = 1; @@ -307,7 +309,7 @@ void renderer_copy_texture(struct renderer *ctx, /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -345,7 +347,7 @@ void renderer_copy_texture(struct renderer *ctx, vg_set_viewport(ctx->owner, VEGA_Y0_TOP); /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &src); + cso_set_fragment_sampler_views(ctx->cso, 1, &src); /* shaders */ cso_set_vertex_shader_handle(ctx->cso, vg_texture_vs(ctx->owner)); @@ -385,7 +387,7 @@ void renderer_copy_texture(struct renderer *ctx, /* restore state we changed */ cso_restore_blend(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_vertex_shader(ctx->cso); cso_restore_fragment_shader(ctx->cso); @@ -406,6 +408,8 @@ void renderer_copy_surface(struct renderer *ctx, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_buffer *buf; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; struct pipe_texture texTemp, *tex; struct pipe_surface *texSurf; struct pipe_framebuffer_state fb; @@ -457,6 +461,12 @@ void renderer_copy_surface(struct renderer *ctx, if (!tex) return; + u_sampler_view_default_template(&view_templ, tex, tex->format); + view = pipe->create_sampler_view(pipe, tex, &view_templ); + + if (!view) + return; + texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -479,7 +489,7 @@ void renderer_copy_surface(struct renderer *ctx, /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -515,7 +525,7 @@ void renderer_copy_surface(struct renderer *ctx, } /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &tex); + cso_set_fragment_sampler_views(ctx->cso, 1, &view); /* shaders */ cso_set_fragment_shader_handle(ctx->cso, ctx->fs); @@ -552,13 +562,14 @@ void renderer_copy_surface(struct renderer *ctx, /* restore state we changed */ cso_restore_blend(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); cso_restore_viewport(ctx->cso); pipe_texture_reference(&tex, NULL); + pipe_sampler_view_reference(&view, NULL); } void renderer_texture_quad(struct renderer *r, diff --git a/src/gallium/state_trackers/vega/renderer.h b/src/gallium/state_trackers/vega/renderer.h index 990cd32c313..03366f13614 100644 --- a/src/gallium/state_trackers/vega/renderer.h +++ b/src/gallium/state_trackers/vega/renderer.h @@ -33,6 +33,7 @@ struct renderer; struct vg_context; struct pipe_texture; +struct pipe_sampler_view; struct pipe_surface; struct renderer *renderer_create(struct vg_context *owner); @@ -57,7 +58,7 @@ void renderer_texture_quad(struct renderer *, VGfloat x3, VGfloat y3, VGfloat x4, VGfloat y4); void renderer_copy_texture(struct renderer *r, - struct pipe_texture *src, + struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, struct pipe_texture *dst, diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c index 0e71a507bff..f2ec24c57ff 100644 --- a/src/gallium/state_trackers/vega/shader.c +++ b/src/gallium/state_trackers/vega/shader.c @@ -119,7 +119,7 @@ static void setup_constant_buffer(struct shader *shader) static VGint blend_bind_samplers(struct vg_context *ctx, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { VGBlendMode bmode = ctx->state.vg.blend_mode; @@ -132,15 +132,15 @@ static VGint blend_bind_samplers(struct vg_context *ctx, vg_prepare_blend_surface(ctx); samplers[2] = &ctx->blend_sampler; - textures[2] = stfb->blend_texture; + sampler_views[2] = stfb->blend_texture_view; - if (!samplers[0] || !textures[0]) { + if (!samplers[0] || !sampler_views[0]) { samplers[0] = samplers[2]; - textures[0] = textures[2]; + sampler_views[0] = sampler_views[2]; } - if (!samplers[1] || !textures[1]) { + if (!samplers[1] || !sampler_views[1]) { samplers[1] = samplers[0]; - textures[1] = textures[0]; + sampler_views[1] = sampler_views[0]; } return 1; @@ -151,7 +151,7 @@ static VGint blend_bind_samplers(struct vg_context *ctx, static void setup_samplers(struct shader *shader) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct vg_context *ctx = shader->context; /* a little wonky: we use the num as a boolean that just says * whether any sampler/textures have been set. the actual numbering @@ -167,20 +167,20 @@ static void setup_samplers(struct shader *shader) samplers[1] = NULL; samplers[2] = NULL; samplers[3] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; - textures[3] = NULL; - - num += paint_bind_samplers(shader->paint, samplers, textures); - num += mask_bind_samplers(samplers, textures); - num += blend_bind_samplers(ctx, samplers, textures); + sampler_views[0] = NULL; + sampler_views[1] = NULL; + sampler_views[2] = NULL; + sampler_views[3] = NULL; + + num += paint_bind_samplers(shader->paint, samplers, sampler_views); + num += mask_bind_samplers(samplers, sampler_views); + num += blend_bind_samplers(ctx, samplers, sampler_views); if (shader->drawing_image && shader->image) - num += image_bind_samplers(shader->image, samplers, textures); + num += image_bind_samplers(shader->image, samplers, sampler_views); if (num) { cso_set_samplers(ctx->cso_context, 4, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, 4, textures); + cso_set_fragment_sampler_views(ctx->cso_context, 4, sampler_views); } } diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c index 7769112a31e..11ebbbe5444 100644 --- a/src/gallium/state_trackers/vega/vg_context.c +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -43,6 +43,7 @@ #include "util/u_simple_shaders.h" #include "util/u_memory.h" #include "util/u_blit.h" +#include "util/u_sampler.h" struct vg_context *_vg_context = 0; @@ -436,19 +437,24 @@ void vg_prepare_blend_surface(struct vg_context *ctx) { struct pipe_surface *dest_surface = NULL; struct pipe_context *pipe = ctx->pipe; + struct pipe_sampler_view *view; + struct pipe_sampler_view view_templ; struct st_framebuffer *stfb = ctx->draw_buffer; struct st_renderbuffer *strb = stfb->strb; /* first finish all pending rendering */ vgFinish(); + u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format); + view = pipe->create_sampler_view(pipe, strb->texture, &view_templ); + dest_surface = pipe->screen->get_tex_surface(pipe->screen, - stfb->blend_texture, + stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, - strb->texture, + view, 0, strb->height, strb->width, 0, dest_surface, @@ -461,6 +467,8 @@ void vg_prepare_blend_surface(struct vg_context *ctx) /* make sure it's complete */ vgFinish(); + + pipe_sampler_view_reference(&view, NULL); } @@ -477,13 +485,13 @@ void vg_prepare_blend_surface_from_mask(struct vg_context *ctx) vgFinish(); dest_surface = pipe->screen->get_tex_surface(pipe->screen, - stfb->blend_texture, + stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, - stfb->alpha_mask, + stfb->alpha_mask_view, 0, strb->height, strb->width, 0, dest_surface, diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h index 17c7d2ad1c5..c9e36d7d767 100644 --- a/src/gallium/state_trackers/vega/vg_context.h +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -55,9 +55,10 @@ struct st_framebuffer { struct st_renderbuffer *strb; struct st_renderbuffer *dsrb; - struct pipe_texture *alpha_mask; + struct pipe_sampler_view *alpha_mask_view; + + struct pipe_sampler_view *blend_texture_view; - struct pipe_texture *blend_texture; struct st_framebuffer_iface *iface; enum st_attachment_type strb_att; diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c index ea5c2ce41f6..f438e34087e 100644 --- a/src/gallium/state_trackers/vega/vg_tracker.c +++ b/src/gallium/state_trackers/vega/vg_tracker.c @@ -32,6 +32,7 @@ #include "util/u_inlines.h" #include "pipe/p_screen.h" #include "util/u_format.h" +#include "util/u_sampler.h" #include "util/u_memory.h" #include "util/u_math.h" #include "util/u_rect.h" @@ -41,7 +42,7 @@ PUBLIC const int st_api_OpenVG = 1; static struct pipe_texture * create_texture(struct pipe_context *pipe, enum pipe_format format, - VGint width, VGint height) + VGint width, VGint height) { struct pipe_texture templ; @@ -71,6 +72,27 @@ create_texture(struct pipe_context *pipe, enum pipe_format format, return pipe->screen->texture_create(pipe->screen, &templ); } +static struct pipe_sampler_view * +create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture(pipe, format, width, height); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + /** * Allocate a renderbuffer for a an on-screen window (not a user-created * renderbuffer). The window system code determines the format. @@ -115,8 +137,8 @@ st_renderbuffer_alloc_storage(struct vg_context * ctx, surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); - strb->texture = create_texture(pipe, strb->format, - width, height); + strb->texture = create_texture(pipe, strb->format, width, height); + if (!strb->texture) return FALSE; @@ -191,7 +213,7 @@ struct st_framebuffer * st_create_framebuffer(const void *visual, /*### currently we always allocate it but it's possible it's not necessary if EGL_ALPHA_MASK_SIZE was 0 */ - stfb->alpha_mask = 0; + stfb->alpha_mask_view = NULL; stfb->width = width; stfb->height = height; @@ -206,19 +228,19 @@ static void setup_new_alpha_mask(struct vg_context *ctx, uint width, uint height) { struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *old_texture = stfb->alpha_mask; + struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view; /* we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to this texture and use it as a sampler, so while this wastes some space it makes both of those a lot simpler */ - stfb->alpha_mask = - create_texture(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); + stfb->alpha_mask_view = + create_tex_and_view(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); - if (!stfb->alpha_mask) { - if (old_texture) - pipe_texture_reference(&old_texture, NULL); + if (!stfb->alpha_mask_view) { + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); return; } @@ -228,15 +250,15 @@ static void setup_new_alpha_mask(struct vg_context *ctx, mask_fill(0, 0, width, height, 1.f); /* if we had an old surface copy it over */ - if (old_texture) { + if (old_sampler_view) { struct pipe_surface *surface = pipe->screen->get_tex_surface( pipe->screen, - stfb->alpha_mask, + stfb->alpha_mask_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); struct pipe_surface *old_surface = pipe->screen->get_tex_surface( pipe->screen, - old_texture, + old_sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); if (pipe->surface_copy) { @@ -264,8 +286,8 @@ static void setup_new_alpha_mask(struct vg_context *ctx, /* Free the old texture */ - if (old_texture) - pipe_texture_reference(&old_texture, NULL); + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); } void st_resize_framebuffer(struct st_framebuffer *stfb, @@ -326,9 +348,9 @@ void st_resize_framebuffer(struct st_framebuffer *stfb, setup_new_alpha_mask(ctx, stfb, width, height); - pipe_texture_reference( &stfb->blend_texture, NULL ); - stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, - width, height); + pipe_sampler_view_reference( &stfb->blend_texture_view, NULL ); + stfb->blend_texture_view = create_tex_and_view(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, + width, height); } void st_set_framebuffer_surface(struct st_framebuffer *stfb, -- 2.30.2