X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_blitter.c;h=956aedc8a15a66af726912450a9a894d80d6e9c3;hb=c7f5c9a3dc6350252e73b541bb85ab3ed9e64a9c;hp=36d582491f36e3390c358e34e147c9acd4a949ef;hpb=275c4bd3643d773210780cb8d578ca84f2604684;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 36d582491f3..956aedc8a15 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -45,6 +45,7 @@ #include "util/u_draw_quad.h" #include "util/u_pack_color.h" #include "util/u_rect.h" +#include "util/u_sampler.h" #include "util/u_simple_shaders.h" #include "util/u_texture.h" @@ -55,7 +56,7 @@ struct blitter_context_priv struct blitter_context blitter; struct pipe_context *pipe; /**< pipe context */ - struct pipe_buffer *vbuf; /**< quad */ + struct pipe_resource *vbuf; /**< quad */ float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */ @@ -96,6 +97,8 @@ struct blitter_context_priv /* Rasterizer state. */ void *rs_state; + struct pipe_sampler_view *sampler_view; + /* Viewport state. */ struct pipe_viewport_state viewport; @@ -127,8 +130,9 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) ctx->blitter.saved_vs = INVALID_PTR; ctx->blitter.saved_velem_state = INVALID_PTR; ctx->blitter.saved_fb_state.nr_cbufs = ~0; - ctx->blitter.saved_num_textures = ~0; + ctx->blitter.saved_num_sampler_views = ~0; ctx->blitter.saved_num_sampler_states = ~0; + ctx->blitter.saved_num_vertex_buffers = ~0; /* blend state objects */ memset(&blend, 0, sizeof(blend)); @@ -165,6 +169,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) sampler_state->wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler_state->wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler_state->wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler_state->normalized_coords = TRUE; /* The sampler state objects which sample from a specified mipmap level * are created on-demand. */ @@ -212,8 +217,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) /* create the vertex buffer */ ctx->vbuf = pipe_buffer_create(ctx->pipe->screen, - 32, - PIPE_BUFFER_USAGE_VERTEX, + PIPE_BIND_VERTEX_BUFFER, sizeof(ctx->vertices)); return &ctx->blitter; @@ -252,7 +256,11 @@ void util_blitter_destroy(struct blitter_context *blitter) if (ctx->sampler_state[i]) pipe->delete_sampler_state(pipe, ctx->sampler_state[i]); - pipe_buffer_reference(&ctx->vbuf, NULL); + if (ctx->sampler_view) { + pipe_sampler_view_reference(&ctx->sampler_view, NULL); + } + + pipe_resource_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -305,11 +313,18 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx) ctx->blitter.saved_num_sampler_states = ~0; } - if (ctx->blitter.saved_num_textures != ~0) { - pipe->set_fragment_sampler_textures(pipe, - ctx->blitter.saved_num_textures, - ctx->blitter.saved_textures); - ctx->blitter.saved_num_textures = ~0; + if (ctx->blitter.saved_num_sampler_views != ~0) { + pipe->set_fragment_sampler_views(pipe, + ctx->blitter.saved_num_sampler_views, + ctx->blitter.saved_sampler_views); + ctx->blitter.saved_num_sampler_views = ~0; + } + + if (ctx->blitter.saved_num_vertex_buffers != ~0) { + pipe->set_vertex_buffers(pipe, + ctx->blitter.saved_num_vertex_buffers, + ctx->blitter.saved_vertex_buffers); + ctx->blitter.saved_num_vertex_buffers = ~0; } } @@ -444,7 +459,7 @@ static void blitter_draw_quad(struct blitter_context_priv *ctx) struct pipe_context *pipe = ctx->pipe; /* write vertices and draw them */ - pipe_buffer_write(pipe->screen, ctx->vbuf, + pipe_buffer_write(pipe, ctx->vbuf, 0, sizeof(ctx->vertices), ctx->vertices); util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, @@ -621,9 +636,10 @@ static void util_blitter_do_copy(struct blitter_context *blitter, struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->pipe; struct pipe_framebuffer_state fb_state; + struct pipe_sampler_view viewTempl, *view; assert(blitter->saved_fb_state.nr_cbufs != ~0); - assert(blitter->saved_num_textures != ~0); + assert(blitter->saved_num_sampler_views != ~0); assert(blitter->saved_num_sampler_states != ~0); assert(src->texture->target < PIPE_MAX_TEXTURE_TYPES); @@ -651,12 +667,24 @@ static void util_blitter_do_copy(struct blitter_context *blitter, fb_state.zsbuf = 0; } + u_sampler_view_default_template(&viewTempl, + src->texture, + src->texture->format); + view = pipe->create_sampler_view(pipe, + src->texture, + &viewTempl); + + if (ctx->sampler_view) { + pipe_sampler_view_reference(&ctx->sampler_view, NULL); + } + ctx->sampler_view = view; + pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_vs_state(pipe, ctx->vs_tex); pipe->bind_fragment_sampler_states(pipe, 1, blitter_get_sampler_state(ctx, src->level)); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); - pipe->set_fragment_sampler_textures(pipe, 1, &src->texture); + pipe->set_fragment_sampler_views(pipe, 1, &view); pipe->set_framebuffer_state(pipe, &fb_state); /* set texture coordinates */ @@ -694,8 +722,8 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture texTemp; - struct pipe_texture *texture; + struct pipe_resource texTemp; + struct pipe_resource *texture; struct pipe_surface *tex_surf; /* check whether the states are properly saved */ @@ -709,13 +737,13 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, texTemp.height0 = height; texTemp.depth0 = 1; - texture = screen->texture_create(screen, &texTemp); + texture = screen->resource_create(screen, &texTemp); if (!texture) return; tex_surf = screen->get_tex_surface(screen, texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION); /* blit from the src to the temp */ util_blitter_do_copy(blitter, tex_surf, 0, 0, @@ -727,7 +755,7 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, width, height, FALSE); pipe_surface_reference(&tex_surf, NULL); - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); blitter_restore_CSOs(ctx); } @@ -761,8 +789,8 @@ void util_blitter_copy(struct blitter_context *blitter, is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; is_stencil = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 1) != 0; - dst_tex_usage = is_depth || is_stencil ? PIPE_TEXTURE_USAGE_DEPTH_STENCIL : - PIPE_TEXTURE_USAGE_RENDER_TARGET; + dst_tex_usage = is_depth || is_stencil ? PIPE_BIND_DEPTH_STENCIL : + PIPE_BIND_RENDER_TARGET; /* check if we can sample from and render to the surfaces */ /* (assuming copying a stencil buffer is not possible) */ @@ -770,7 +798,7 @@ void util_blitter_copy(struct blitter_context *blitter, !screen->is_format_supported(screen, dst->format, dst->texture->target, dst_tex_usage, 0) || !screen->is_format_supported(screen, src->format, src->texture->target, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { util_surface_copy(pipe, FALSE, dst, dstx, dsty, src, srcx, srcy, width, height); return; @@ -807,7 +835,7 @@ void util_blitter_fill(struct blitter_context *blitter, /* check if we can render to the surface */ if (util_format_is_depth_or_stencil(dst->format) || /* unlikely, but you never know */ !screen->is_format_supported(screen, dst->format, dst->texture->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + PIPE_BIND_RENDER_TARGET, 0)) { util_surface_fill(pipe, dst, dstx, dsty, width, height, value); return; }