summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorBrian <[email protected]>2008-03-19 11:12:48 -0600
committerBrian <[email protected]>2008-03-19 11:14:18 -0600
commit7d95efde0a0e13e13c59444703bc47eb13926385 (patch)
tree807dbe0e71c0c98534fef1957b7317acd306c3a5 /src/gallium/auxiliary/util
parent1213c7257335d577cf0217e34edafddf0451ba1b (diff)
gallium: implement CSO save/restore functions for use by meta operations (blit, gen-mipmaps, quad-clear, etc)
Also, additional cso_set_*() functions for viewport, framebuffer, blend color, etc. state.
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_blit.c125
-rw-r--r--src/gallium/auxiliary/util/u_blit.h5
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c116
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.h6
4 files changed, 130 insertions, 122 deletions
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 4b4ab8185f2..123304fe68e 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -45,15 +45,18 @@
#include "util/u_blit.h"
#include "util/u_simple_shaders.h"
+#include "cso_cache/cso_context.h"
+
struct blit_state
{
struct pipe_context *pipe;
+ struct cso_context *cso;
- void *blend;
- void *depthstencil;
- void *rasterizer;
- void *samplers[2]; /* one for linear, one for nearest sampling */
+ struct pipe_blend_state blend;
+ struct pipe_depth_stencil_alpha_state depthstencil;
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_sampler_state sampler;
/*struct pipe_viewport_state viewport;*/
struct pipe_sampler_state *vs;
@@ -66,56 +69,44 @@ struct blit_state
* Intended to be created once and re-used for many blit() calls.
*/
struct blit_state *
-util_create_blit(struct pipe_context *pipe)
+util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
{
- struct pipe_blend_state blend;
- struct pipe_depth_stencil_alpha_state depthstencil;
- struct pipe_rasterizer_state rasterizer;
struct blit_state *ctx;
- struct pipe_sampler_state sampler;
ctx = CALLOC_STRUCT(blit_state);
if (!ctx)
return NULL;
ctx->pipe = pipe;
+ ctx->cso = cso;
- /* we don't use blending, but need to set valid values */
- memset(&blend, 0, sizeof(blend));
- blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.colormask = PIPE_MASK_RGBA;
- ctx->blend = pipe->create_blend_state(pipe, &blend);
+ /* disabled blending/masking */
+ memset(&ctx->blend, 0, sizeof(ctx->blend));
+ ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+ ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+ ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ ctx->blend.colormask = PIPE_MASK_RGBA;
- /* depth/stencil/alpha */
- memset(&depthstencil, 0, sizeof(depthstencil));
- ctx->depthstencil = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil);
+ /* no-op depth/stencil/alpha */
+ memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
/* rasterizer */
- memset(&rasterizer, 0, sizeof(rasterizer));
- rasterizer.front_winding = PIPE_WINDING_CW;
- rasterizer.cull_mode = PIPE_WINDING_NONE;
- rasterizer.bypass_clipping = 1; /* bypasses viewport too */
- /*rasterizer.bypass_vs = 1;*/
- ctx->rasterizer = pipe->create_rasterizer_state(pipe, &rasterizer);
+ memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
+ ctx->rasterizer.front_winding = PIPE_WINDING_CW;
+ ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
+ ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */
+ /*ctx->rasterizer.bypass_vs = 1;*/
/* samplers */
- memset(&sampler, 0, sizeof(sampler));
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
- sampler.normalized_coords = 1;
- ctx->samplers[0] = pipe->create_sampler_state(pipe, &sampler);
-
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
- ctx->samplers[1] = pipe->create_sampler_state(pipe, &sampler);
-
+ memset(&ctx->sampler, 0, sizeof(ctx->sampler));
+ ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ ctx->sampler.min_img_filter = 0; /* set later */
+ ctx->sampler.mag_img_filter = 0; /* set later */
+ ctx->sampler.normalized_coords = 1;
#if 0
/* viewport */
@@ -153,12 +144,6 @@ util_destroy_blit(struct blit_state *ctx)
{
struct pipe_context *pipe = ctx->pipe;
- pipe->delete_blend_state(pipe, ctx->blend);
- pipe->delete_depth_stencil_alpha_state(pipe, ctx->depthstencil);
- pipe->delete_rasterizer_state(pipe, ctx->rasterizer);
- pipe->delete_sampler_state(pipe, ctx->samplers[0]);
- pipe->delete_sampler_state(pipe, ctx->samplers[1]);
-
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_fs_state(pipe, ctx->fs);
@@ -236,17 +221,24 @@ util_blit_pixels(struct blit_state *ctx,
src, srcLeft, srcTop, /* src */
srcW, srcH); /* size */
- /* drawing dest */
- memset(&fb, 0, sizeof(fb));
- fb.num_cbufs = 1;
- fb.cbufs[0] = dst;
- pipe->set_framebuffer_state(pipe, &fb);
+ /* save state (restored below) */
+ cso_save_blend(ctx->cso);
+ cso_save_depth_stencil_alpha(ctx->cso);
+ cso_save_rasterizer(ctx->cso);
+ cso_save_samplers(ctx->cso);
+ cso_save_sampler_textures(ctx->cso);
+ cso_save_framebuffer(ctx->cso);
+
+ /* set misc state we care about */
+ cso_set_blend(ctx->cso, &ctx->blend);
+ cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
+ cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
/* sampler */
- if (filter == PIPE_TEX_MIPFILTER_NEAREST)
- pipe->bind_sampler_states(pipe, 1, &ctx->samplers[0]);
- else
- pipe->bind_sampler_states(pipe, 1, &ctx->samplers[1]);
+ ctx->sampler.min_img_filter = filter;
+ ctx->sampler.mag_img_filter = filter;
+ cso_single_sampler(ctx->cso, 0, &ctx->sampler);
+ cso_single_sampler_done(ctx->cso);
/* texture */
pipe->set_sampler_textures(pipe, 1, &tex);
@@ -255,22 +247,25 @@ util_blit_pixels(struct blit_state *ctx,
pipe->bind_fs_state(pipe, ctx->fs);
pipe->bind_vs_state(pipe, ctx->vs);
- /* misc state */
- pipe->bind_blend_state(pipe, ctx->blend);
- pipe->bind_depth_stencil_alpha_state(pipe, ctx->depthstencil);
- pipe->bind_rasterizer_state(pipe, ctx->rasterizer);
+ /* drawing dest */
+ memset(&fb, 0, sizeof(fb));
+ fb.num_cbufs = 1;
+ fb.cbufs[0] = dst;
+ cso_set_framebuffer(ctx->cso, &fb);
/* draw quad */
util_draw_texquad(pipe, dstX0, dstY0, dstX1, dstY1, z);
- /* unbind */
- pipe->set_sampler_textures(pipe, 0, NULL);
- pipe->bind_sampler_states(pipe, 0, NULL);
+ /* restore state we changed */
+ cso_restore_blend(ctx->cso);
+ cso_restore_depth_stencil_alpha(ctx->cso);
+ cso_restore_rasterizer(ctx->cso);
+ cso_restore_samplers(ctx->cso);
+ cso_restore_sampler_textures(ctx->cso);
+ cso_restore_framebuffer(ctx->cso);
- /* free stuff */
+ /* free the texture */
pipe_surface_reference(&texSurf, NULL);
screen->texture_release(screen, &tex);
-
- /* Note: caller must restore pipe/gallium state at this time */
}
diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h
index a349be99ad8..61f1d9bb32a 100644
--- a/src/gallium/auxiliary/util/u_blit.h
+++ b/src/gallium/auxiliary/util/u_blit.h
@@ -30,15 +30,16 @@
#define U_BLIT_H
+
struct pipe_context;
struct pipe_surface;
+struct cso_context;
struct blit_state;
-
extern struct blit_state *
-util_create_blit(struct pipe_context *pipe);
+util_create_blit(struct pipe_context *pipe, struct cso_context *cso);
extern void
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index e18f8ab72ac..27141c4d13f 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -49,14 +49,18 @@
#include "tgsi/util/tgsi_dump.h"
#include "tgsi/util/tgsi_parse.h"
+#include "cso_cache/cso_context.h"
+
struct gen_mipmap_state
{
struct pipe_context *pipe;
+ struct cso_context *cso;
- void *blend;
- void *depthstencil;
- void *rasterizer;
+ struct pipe_blend_state blend;
+ struct pipe_depth_stencil_alpha_state depthstencil;
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_sampler_state sampler;
/*struct pipe_viewport_state viewport;*/
struct pipe_sampler_state *vs;
struct pipe_sampler_state *fs;
@@ -675,11 +679,9 @@ fallback_gen_mipmap(struct gen_mipmap_state *ctx,
* generate a mipmap.
*/
struct gen_mipmap_state *
-util_create_gen_mipmap(struct pipe_context *pipe)
+util_create_gen_mipmap(struct pipe_context *pipe,
+ struct cso_context *cso)
{
- struct pipe_blend_state blend;
- struct pipe_depth_stencil_alpha_state depthstencil;
- struct pipe_rasterizer_state rasterizer;
struct gen_mipmap_state *ctx;
ctx = CALLOC_STRUCT(gen_mipmap_state);
@@ -687,27 +689,36 @@ util_create_gen_mipmap(struct pipe_context *pipe)
return NULL;
ctx->pipe = pipe;
+ ctx->cso = cso;
- /* we don't use blending, but need to set valid values */
- memset(&blend, 0, sizeof(blend));
- blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.colormask = PIPE_MASK_RGBA;
- ctx->blend = pipe->create_blend_state(pipe, &blend);
+ /* disabled blending/masking */
+ memset(&ctx->blend, 0, sizeof(ctx->blend));
+ ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+ ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+ ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ ctx->blend.colormask = PIPE_MASK_RGBA;
- /* depth/stencil/alpha */
- memset(&depthstencil, 0, sizeof(depthstencil));
- ctx->depthstencil = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil);
+ /* no-op depth/stencil/alpha */
+ memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
/* rasterizer */
- memset(&rasterizer, 0, sizeof(rasterizer));
- rasterizer.front_winding = PIPE_WINDING_CW;
- rasterizer.cull_mode = PIPE_WINDING_NONE;
- rasterizer.bypass_clipping = 1; /* bypasses viewport too */
- //rasterizer.bypass_vs = 1;
- ctx->rasterizer = pipe->create_rasterizer_state(pipe, &rasterizer);
+ memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
+ ctx->rasterizer.front_winding = PIPE_WINDING_CW;
+ ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
+ ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */
+ /*ctx->rasterizer.bypass_vs = 1;*/
+
+ /* sampler state */
+ memset(&ctx->sampler, 0, sizeof(ctx->sampler));
+ ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
+ ctx->sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
+ ctx->sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
+ ctx->sampler.normalized_coords = 1;
+
#if 0
/* viewport */
@@ -745,9 +756,6 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
{
struct pipe_context *pipe = ctx->pipe;
- pipe->delete_blend_state(pipe, ctx->blend);
- pipe->delete_depth_stencil_alpha_state(pipe, ctx->depthstencil);
- pipe->delete_rasterizer_state(pipe, ctx->rasterizer);
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_fs_state(pipe, ctx->fs);
@@ -792,8 +800,6 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_framebuffer_state fb;
- struct pipe_sampler_state sampler;
- void *sampler_cso;
uint dstLevel;
uint zslice = 0;
@@ -803,30 +809,29 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
return;
}
- /* init framebuffer state */
- memset(&fb, 0, sizeof(fb));
- fb.num_cbufs = 1;
-
- /* sampler state */
- memset(&sampler, 0, sizeof(sampler));
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
- sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
- sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
- sampler.normalized_coords = 1;
+ /* save state (restored below) */
+ cso_save_blend(ctx->cso);
+ cso_save_depth_stencil_alpha(ctx->cso);
+ cso_save_rasterizer(ctx->cso);
+ cso_save_samplers(ctx->cso);
+ cso_save_sampler_textures(ctx->cso);
+ cso_save_framebuffer(ctx->cso);
/* bind our state */
- pipe->bind_blend_state(pipe, ctx->blend);
- pipe->bind_depth_stencil_alpha_state(pipe, ctx->depthstencil);
- pipe->bind_rasterizer_state(pipe, ctx->rasterizer);
+ cso_set_blend(ctx->cso, &ctx->blend);
+ cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
+ cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
+
pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_fs_state(pipe, ctx->fs);
#if 0
pipe->set_viewport_state(pipe, &ctx->viewport);
#endif
+ /* init framebuffer state */
+ memset(&fb, 0, sizeof(fb));
+ fb.num_cbufs = 1;
+
/*
* XXX for small mipmap levels, it may be faster to use the software
* fallback path...
@@ -838,7 +843,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
* Setup framebuffer / dest surface
*/
fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice);
- pipe->set_framebuffer_state(pipe, &fb);
+ cso_set_framebuffer(ctx->cso, &fb);
/*
* Setup sampler state
@@ -847,11 +852,10 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
* has trouble with min clamping so we also set the lod_bias to
* try to work around that.
*/
- sampler.min_lod = sampler.max_lod = (float) srcLevel;
- sampler.lod_bias = (float) srcLevel;
- sampler_cso = pipe->create_sampler_state(pipe, &sampler);
- pipe->bind_sampler_states(pipe, 1, &sampler_cso);
-
+ ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel;
+ ctx->sampler.lod_bias = (float) srcLevel;
+ cso_single_sampler(ctx->cso, 0, &ctx->sampler);
+ cso_single_sampler_done(ctx->cso);
#if 0
simple_viewport(pipe, pt->width[dstLevel], pt->height[dstLevel]);
#endif
@@ -869,9 +873,13 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
pipe->flush(pipe, PIPE_FLUSH_WAIT);
/*pipe->texture_update(pipe, pt); not really needed */
-
- pipe->delete_sampler_state(pipe, sampler_cso);
}
- /* Note: caller must restore pipe/gallium state at this time */
+ /* restore state we changed */
+ cso_restore_blend(ctx->cso);
+ cso_restore_depth_stencil_alpha(ctx->cso);
+ cso_restore_rasterizer(ctx->cso);
+ cso_restore_samplers(ctx->cso);
+ cso_restore_sampler_textures(ctx->cso);
+ cso_restore_framebuffer(ctx->cso);
}
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h
index 80496140a24..eeabf3bf075 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.h
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.h
@@ -31,11 +31,15 @@
#include "pipe/p_state.h"
+struct pipe_context;
+struct pipe_texture;
+struct cso_context;
+
struct gen_mipmap_state;
extern struct gen_mipmap_state *
-util_create_gen_mipmap(struct pipe_context *pipe);
+util_create_gen_mipmap(struct pipe_context *pipe, struct cso_context *cso);
extern void