On Sun, 2009-12-13 at 15:27 -0800, Marek Olšák wrote:
> -- /dev/null
> +++ b/src/gallium/auxiliary/util/u_blitter.c
> @@ -0,0 +1,605 @@
> +/**************************************************************************
> + *
> + * Copyright 2009 Marek Olšák <[email protected]>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
> + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +/**
> + * @file
> + * Blitter utility to facilitate acceleration of the clear, surface_copy,
> + * and surface_fill functions.
> + *
> + * @author Marek Olšák
> + */
> +
> +#include "pipe/p_context.h"
> +#include "pipe/p_defines.h"
> +#include "pipe/p_inlines.h"
> +#include "pipe/p_shader_tokens.h"
> +#include "pipe/p_state.h"
> +
> +#include "util/u_memory.h"
> +#include "util/u_math.h"
> +#include "util/u_blitter.h"
> +#include "util/u_draw_quad.h"
> +#include "util/u_pack_color.h"
> +#include "util/u_rect.h"
> +#include "util/u_simple_shaders.h"
> +#include "util/u_texture.h"
> +
> +struct blitter_context_priv
> +{
> + struct blitter_context blitter;
> +
> + struct pipe_context *pipe; /**< pipe context */
> + struct pipe_buffer *vbuf; /**< quad */
> +
> + float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */
> +
> + /* Constant state objects. */
> + /* Vertex shaders. */
> + void *vs_col; /**< Vertex shader which passes {pos, color} to the output
> */
> + void *vs_tex; /**<Vertex shader which passes {pos, texcoord} to the
> output.*/
> +
> + /* Fragment shaders. */
> + void *fs_col[8]; /**< FS which outputs colors to 1-8 color buffers */
> + void *fs_texfetch_col[4]; /**< FS which outputs a color from a texture
> */
> + void *fs_texfetch_depth[4]; /**< FS which outputs a depth from a texture,
> + where the index is PIPE_TEXTURE_* to be
> sampled */
Please use PIPE_MAX_COLOR_BUFS or other defines to size these arrays.
> + /* Blend state. */
> + void *blend_write_color; /**< blend state with writemask of RGBA */
> + void *blend_keep_color; /**< blend state with writemask of 0 */
> +
> + /* Depth stencil alpha state. */
> + void *dsa_write_depth_stencil[0xff]; /**< indices are stencil clear
> values */
That's a lot of state objects...
> + void *dsa_write_depth_keep_stencil;
> + void *dsa_keep_depth_stencil;
> +
> + /* Other state. */
> + void *sampler_state[16]; /**< sampler state for clamping to a miplevel
> */
> + void *rs_state; /**< rasterizer state */
> +};
> +
> +struct blitter_context *util_blitter_create(struct pipe_context *pipe)
> +{
> + struct blitter_context_priv *ctx;
> + struct pipe_blend_state blend;
> + struct pipe_depth_stencil_alpha_state dsa;
> + struct pipe_rasterizer_state rs_state;
> + struct pipe_sampler_state sampler_state;
> + unsigned i, max_render_targets;
> +
> + ctx = CALLOC_STRUCT(blitter_context_priv);
> + if (!ctx)
> + return NULL;
> +
> + ctx->pipe = pipe;
> +
> + /* init state objects for them to be considered invalid */
> + ctx->blitter.saved_fb_state.nr_cbufs = ~0;
> + ctx->blitter.saved_num_textures = ~0;
> + ctx->blitter.saved_num_sampler_states = ~0;
> +
> + /* blend state objects */
> + memset(&blend, 0, sizeof(blend));
> + ctx->blend_keep_color = pipe->create_blend_state(pipe, &blend);
> +
> + blend.colormask = PIPE_MASK_RGBA;
> + ctx->blend_write_color = pipe->create_blend_state(pipe, &blend);
> +
> + /* depth stencil alpha state objects */
> + memset(&dsa, 0, sizeof(dsa));
> + ctx->dsa_keep_depth_stencil =
> + pipe->create_depth_stencil_alpha_state(pipe, &dsa);
> +
> + dsa.depth.enabled = 1;
> + dsa.depth.writemask = 1;
> + dsa.depth.func = PIPE_FUNC_ALWAYS;
> + ctx->dsa_write_depth_keep_stencil =
> + pipe->create_depth_stencil_alpha_state(pipe, &dsa);
> +
> + dsa.stencil[0].enabled = 1;
> + dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
> + dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
> + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
> + dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
> + dsa.stencil[0].valuemask = 0xff;
> + dsa.stencil[0].writemask = 0xff;
> +
> + /* create a depth stencil alpha state for each possible stencil clear
> + * value */
> + for (i = 0; i < 0xff; i++) {
> + dsa.stencil[0].ref_value = i;
> +
> + ctx->dsa_write_depth_stencil[i] =
> + pipe->create_depth_stencil_alpha_state(pipe, &dsa);
> + }
Ouch - that's an unexpectedly large number of state objects being
created for this path.
Can these be created on-demand / lazily?
Can you maybe limit this code to a (much) smaller maximum number of
simultaneously live states of this type? Eg. 4 or 8 of them? Creating
states isn't so terribly expensive, and this seems a bit excessive.
> + /* sampler state */
> + memset(&sampler_state, 0, sizeof(sampler_state));
> + 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;
> +
> + for (i = 0; i < 16; i++) {
> + sampler_state.lod_bias = i;
> + sampler_state.min_lod = i;
> + sampler_state.max_lod = i;
> +
> + ctx->sampler_state[i] = pipe->create_sampler_state(pipe,
> &sampler_state);
> + }
Similarly, create on demand? And use a PIPE_MAX_xxx enum for the loop?
Keith
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev