diff options
author | Michal Krol <michal@vmware.com> | 2010-02-19 19:00:26 +0100 |
---|---|---|
committer | Michal Krol <michal@vmware.com> | 2010-02-19 19:00:26 +0100 |
commit | f6106566081978f663cf08e54bb8908cb58a5316 (patch) | |
tree | 7bc2482548f55471d7024f04c75ac7f58402afa9 /src/gallium/auxiliary/util | |
parent | 3d0bfc6a4be73d43928493641bf819f77075bbc1 (diff) |
gallium: WIP: Introduce sampler views.
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 36 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.h | 24 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_inlines.h | 10 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_sampler.c | 97 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_sampler.h | 57 |
5 files changed, 204 insertions, 20 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 18f8606818..29060a1eff 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" @@ -93,6 +94,8 @@ struct blitter_context_priv /* Rasterizer state. */ void *rs_state; + + struct pipe_sampler_view *sampler_view; }; struct blitter_context *util_blitter_create(struct pipe_context *pipe) @@ -117,7 +120,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) ctx->blitter.saved_fs = INVALID_PTR; ctx->blitter.saved_vs = 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; /* blend state objects */ @@ -230,6 +233,10 @@ void util_blitter_destroy(struct blitter_context *blitter) if (ctx->sampler_state[i]) pipe->delete_sampler_state(pipe, ctx->sampler_state[i]); + if (ctx->sampler_view) { + pipe_sampler_view_reference(&ctx->sampler_view, NULL); + } + pipe_buffer_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -277,11 +284,11 @@ 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; } } @@ -577,9 +584,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); @@ -607,11 +615,23 @@ 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->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 */ diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index a2f17073ac..9911948560 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -50,10 +50,10 @@ struct blitter_context struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */ int saved_num_sampler_states; - void *saved_sampler_states[32]; + void *saved_sampler_states[PIPE_MAX_SAMPLERS]; - int saved_num_textures; - struct pipe_texture *saved_textures[32]; /* is 32 enough? */ + int saved_num_sampler_views; + struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS]; }; /** @@ -218,17 +218,17 @@ void util_blitter_save_fragment_sampler_states( num_sampler_states * sizeof(void *)); } -static INLINE -void util_blitter_save_fragment_sampler_textures( - struct blitter_context *blitter, - int num_textures, - struct pipe_texture **textures) +static INLINE void +util_blitter_save_fragment_sampler_views(struct blitter_context *blitter, + int num_views, + struct pipe_sampler_view **views) { - assert(num_textures <= Elements(blitter->saved_textures)); + assert(num_views <= Elements(blitter->saved_sampler_views)); - blitter->saved_num_textures = num_textures; - memcpy(blitter->saved_textures, textures, - num_textures * sizeof(struct pipe_texture *)); + blitter->saved_num_sampler_views = num_views; + memcpy(blitter->saved_sampler_views, + views, + num_views * sizeof(struct pipe_sampler_view *)); } #ifdef __cplusplus diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e95d58ea86..f8dfea4e51 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -117,6 +117,16 @@ pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex) *ptr = tex; } +static INLINE void +pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view) +{ + struct pipe_sampler_view *old_view = *ptr; + + if (pipe_reference(&(*ptr)->reference, &view->reference)) + old_view->context->sampler_view_destroy(old_view->context, old_view); + *ptr = view; +} + /* * Convenience wrappers for screen buffer functions. diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c new file mode 100644 index 0000000000..3e45a2fa70 --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * 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 VMWARE 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. + * + **************************************************************************/ + + +#include "u_format.h" +#include "u_sampler.h" + + +static void +default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format, + unsigned expand_green_blue) +{ + /* XXX: Check if format is compatible with texture->format. + */ + + view->format = format; + view->first_level = 0; + view->num_levels = texture->last_level + 1; + view->swizzle_r = PIPE_SWIZZLE_RED; + view->swizzle_g = PIPE_SWIZZLE_GREEN; + view->swizzle_b = PIPE_SWIZZLE_BLUE; + view->swizzle_a = PIPE_SWIZZLE_ALPHA; + + /* Override default green and blue component expansion to the requested one. + * + * Gallium expands nonexistent components to (0,0,0,1), DX9 expands to (1,1,1,1). + * Since alpha is always expanded to 1, and red is always present, we only really + * care about green and blue components. + * + * To make it look less hackish, one would have to add UTIL_FORMAT_SWIZZLE_EXPAND + * to indicate components for expansion and then override without exceptions or + * favoring one component over another. + */ + if (format != PIPE_FORMAT_A8_UNORM) { + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (desc) { + if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_g = expand_green_blue; + } + if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_b = expand_green_blue; + } + } + } +} + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format) +{ + /* Expand to (0, 0, 0, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ZERO); +} + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format) +{ + /* Expand to (1, 1, 1, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ONE); +} diff --git a/src/gallium/auxiliary/util/u_sampler.h b/src/gallium/auxiliary/util/u_sampler.h new file mode 100644 index 0000000000..bdd061c851 --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.h @@ -0,0 +1,57 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * 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 VMWARE 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. + * + **************************************************************************/ + + +#ifndef U_SAMPLER_H +#define U_SAMPLER_H + + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format); + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format); + + +#ifdef __cplusplus +} /* extern "C" { */ +#endif + +#endif /* U_SAMPLER_H */ |