summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorMichal Krol <michal@vmware.com>2010-03-02 13:35:30 +0100
committerMichal Krol <michal@vmware.com>2010-03-02 13:35:30 +0100
commit4ca70c489baed3e23dbf5e5e5794385113e22252 (patch)
treec2fb1cc4f46e2ffe2c84ce4680fc68fed29f02de /src/gallium/auxiliary
parentc1c7fa5192c4fb3f51fb67c81e58713d61ff0c93 (diff)
parentff9ddf4d39be9e36d3e1dd9e10e889efa40dfb1e (diff)
Merge branch 'gallium-no-rhw-position'
Conflicts: src/gallium/drivers/r300/r300_blit.c src/gallium/drivers/r300/r300_emit.c src/gallium/drivers/r300/r300_state_derived.c
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c54
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.h13
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c8
-rw-r--r--src/gallium/auxiliary/draw/draw_pt.c4
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c3
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c15
-rw-r--r--src/gallium/auxiliary/util/u_blit.c46
-rw-r--r--src/gallium/auxiliary/util/u_blitter.c47
-rw-r--r--src/gallium/auxiliary/util/u_blitter.h16
-rw-r--r--src/gallium/auxiliary/util/u_dump_state.c1
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c43
11 files changed, 194 insertions, 56 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index b5241fa64c..a7335c340c 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -90,6 +90,9 @@ struct cso_context {
void *fragment_shader, *fragment_shader_saved, *geometry_shader;
void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved;
+ struct pipe_clip_state clip;
+ struct pipe_clip_state clip_saved;
+
struct pipe_framebuffer_state fb, fb_saved;
struct pipe_viewport_state vp, vp_saved;
struct pipe_blend_color blend_color;
@@ -1126,3 +1129,54 @@ void cso_restore_geometry_shader(struct cso_context *ctx)
}
ctx->geometry_shader_saved = NULL;
}
+
+
+/* clip state */
+
+static INLINE void
+clip_state_cpy(struct pipe_clip_state *dst,
+ const struct pipe_clip_state *src)
+{
+ dst->nr = src->nr;
+ if (src->nr) {
+ memcpy(dst->ucp, src->ucp, src->nr * sizeof(src->ucp[0]));
+ }
+}
+
+static INLINE int
+clip_state_cmp(const struct pipe_clip_state *a,
+ const struct pipe_clip_state *b)
+{
+ if (a->nr != b->nr) {
+ return 1;
+ }
+ if (a->nr) {
+ return memcmp(a->ucp, b->ucp, a->nr * sizeof(a->ucp[0]));
+ }
+ return 0;
+}
+
+void
+cso_set_clip(struct cso_context *ctx,
+ const struct pipe_clip_state *clip)
+{
+ if (clip_state_cmp(&ctx->clip, clip)) {
+ clip_state_cpy(&ctx->clip, clip);
+ ctx->pipe->set_clip_state(ctx->pipe, clip);
+ }
+}
+
+void
+cso_save_clip(struct cso_context *ctx)
+{
+ clip_state_cpy(&ctx->clip_saved, &ctx->clip);
+}
+
+void
+cso_restore_clip(struct cso_context *ctx)
+{
+ if (clip_state_cmp(&ctx->clip, &ctx->clip_saved)) {
+ clip_state_cpy(&ctx->clip, &ctx->clip_saved);
+ ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip_saved);
+ }
+}
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index 707b3c2cee..251a9a644f 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -180,6 +180,19 @@ void cso_save_stencil_ref(struct cso_context *cso);
void cso_restore_stencil_ref(struct cso_context *cso);
+/* clip state */
+
+void
+cso_set_clip(struct cso_context *cso,
+ const struct pipe_clip_state *clip);
+
+void
+cso_save_clip(struct cso_context *cso);
+
+void
+cso_restore_clip(struct cso_context *cso);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index d5ddc4a6a9..bb0988543f 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -128,9 +128,7 @@ void draw_set_rasterizer_state( struct draw_context *draw,
draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
draw->rasterizer = raster;
- draw->bypass_clipping =
- ((draw->rasterizer && draw->rasterizer->bypass_vs_clip_and_viewport) ||
- draw->driver.bypass_clipping);
+ draw->bypass_clipping = draw->driver.bypass_clipping;
}
@@ -140,9 +138,7 @@ void draw_set_driver_clipping( struct draw_context *draw,
draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
draw->driver.bypass_clipping = bypass_clipping;
- draw->bypass_clipping =
- ((draw->rasterizer && draw->rasterizer->bypass_vs_clip_and_viewport) ||
- draw->driver.bypass_clipping);
+ draw->bypass_clipping = draw->driver.bypass_clipping;
}
diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c
index 341353f628..6d90a6c42f 100644
--- a/src/gallium/auxiliary/draw/draw_pt.c
+++ b/src/gallium/auxiliary/draw/draw_pt.c
@@ -87,9 +87,7 @@ draw_pt_arrays(struct draw_context *draw,
opt |= PT_CLIPTEST;
}
- if (!draw->rasterizer->bypass_vs_clip_and_viewport) {
- opt |= PT_SHADE;
- }
+ opt |= PT_SHADE;
}
if (opt == 0)
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
index c5dfbcfa3c..1aecb51077 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
@@ -100,8 +100,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
fse->key.nr_elements = MAX2(fse->key.nr_outputs, /* outputs - translate to hw format */
fse->key.nr_inputs); /* inputs - fetch from api format */
- fse->key.viewport = (!draw->rasterizer->bypass_vs_clip_and_viewport &&
- !draw->identity_viewport);
+ fse->key.viewport = !draw->identity_viewport;
fse->key.clip = !draw->bypass_clipping;
fse->key.const_vbuffers = 0;
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
index 56b69354b2..da5106463a 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
@@ -96,8 +96,7 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
*/
draw_pt_post_vs_prepare( fpme->post_vs,
(boolean)draw->bypass_clipping,
- (boolean)(draw->identity_viewport ||
- draw->rasterizer->bypass_vs_clip_and_viewport),
+ (boolean)draw->identity_viewport,
(boolean)draw->rasterizer->gl_rasterization_rules,
(draw->vs.edgeflag_output ? true : false) );
@@ -154,9 +153,7 @@ static void fetch_pipeline_run( struct draw_pt_middle_end *middle,
(char *)pipeline_verts );
/* Run the shader, note that this overwrites the data[] parts of
- * the pipeline verts. If there is no shader, eg if
- * bypass_vs_clip_and_viewport, then the inputs == outputs, and are
- * already in the correct place.
+ * the pipeline verts.
*/
if (opt & PT_SHADE)
{
@@ -239,9 +236,7 @@ static void fetch_pipeline_linear_run( struct draw_pt_middle_end *middle,
(char *)pipeline_verts );
/* Run the shader, note that this overwrites the data[] parts of
- * the pipeline verts. If there is no shader, ie if
- * bypass_vs_clip_and_viewport, then the inputs == outputs, and are
- * already in the correct place.
+ * the pipeline verts.
*/
if (opt & PT_SHADE)
{
@@ -319,9 +314,7 @@ static boolean fetch_pipeline_linear_run_elts( struct draw_pt_middle_end *middle
(char *)pipeline_verts );
/* Run the shader, note that this overwrites the data[] parts of
- * the pipeline verts. If there is no shader, ie if
- * bypass_vs_clip_and_viewport, then the inputs == outputs, and are
- * already in the correct place.
+ * the pipeline verts.
*/
if (opt & PT_SHADE)
{
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index f0bc58a558..0b263a9db5 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -62,6 +62,7 @@ struct blit_state
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
struct pipe_viewport_state viewport;
+ struct pipe_clip_state clip;
void *vs;
void *fs[TGSI_WRITEMASK_XYZW + 1];
@@ -101,7 +102,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
ctx->rasterizer.front_winding = PIPE_WINDING_CW;
ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
- ctx->rasterizer.bypass_vs_clip_and_viewport = 1;
ctx->rasterizer.gl_rasterization_rules = 1;
/* samplers */
@@ -114,7 +114,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
ctx->sampler.mag_img_filter = 0; /* set later */
ctx->sampler.normalized_coords = 1;
-
/* vertex shader - still required to provide the linkage between
* fragment shader input semantics and vertex_element/buffers.
*/
@@ -266,7 +265,6 @@ regions_overlap(int srcX0, int srcY0,
* \param writemask controls which channels in the dest surface are sourced
* from the src surface. Disabled channels are sourced
* from (0,0,0,1).
- * XXX what about clipping???
* XXX need some control over blitting Z and/or stencil.
*/
void
@@ -407,14 +405,17 @@ util_blit_pixels_writemask(struct blit_state *ctx,
cso_save_rasterizer(ctx->cso);
cso_save_samplers(ctx->cso);
cso_save_sampler_textures(ctx->cso);
+ cso_save_viewport(ctx->cso);
cso_save_framebuffer(ctx->cso);
cso_save_fragment_shader(ctx->cso);
cso_save_vertex_shader(ctx->cso);
+ cso_save_clip(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);
+ cso_set_clip(ctx->cso, &ctx->clip);
/* sampler */
ctx->sampler.min_img_filter = filter;
@@ -422,6 +423,17 @@ util_blit_pixels_writemask(struct blit_state *ctx,
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
+ /* viewport */
+ ctx->viewport.scale[0] = 0.5f * dst->width;
+ ctx->viewport.scale[1] = 0.5f * dst->height;
+ ctx->viewport.scale[2] = 0.5f;
+ ctx->viewport.scale[3] = 1.0f;
+ ctx->viewport.translate[0] = 0.5f * dst->width;
+ ctx->viewport.translate[1] = 0.5f * dst->height;
+ ctx->viewport.translate[2] = 0.5f;
+ ctx->viewport.translate[3] = 0.0f;
+ cso_set_viewport(ctx->cso, &ctx->viewport);
+
/* texture */
cso_set_sampler_textures(ctx->cso, 1, &tex);
@@ -444,8 +456,10 @@ util_blit_pixels_writemask(struct blit_state *ctx,
/* draw quad */
offset = setup_vertex_data_tex(ctx,
- (float) dstX0, (float) dstY0,
- (float) dstX1, (float) dstY1,
+ (float) dstX0 / dst->width * 2.0f - 1.0f,
+ (float) dstY0 / dst->height * 2.0f - 1.0f,
+ (float) dstX1 / dst->width * 2.0f - 1.0f,
+ (float) dstY1 / dst->height * 2.0f - 1.0f,
s0, t0,
s1, t1,
z);
@@ -461,9 +475,11 @@ util_blit_pixels_writemask(struct blit_state *ctx,
cso_restore_rasterizer(ctx->cso);
cso_restore_samplers(ctx->cso);
cso_restore_sampler_textures(ctx->cso);
+ cso_restore_viewport(ctx->cso);
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);
cso_restore_vertex_shader(ctx->cso);
+ cso_restore_clip(ctx->cso);
pipe_texture_reference(&tex, NULL);
}
@@ -547,11 +563,13 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_save_framebuffer(ctx->cso);
cso_save_fragment_shader(ctx->cso);
cso_save_vertex_shader(ctx->cso);
+ cso_save_clip(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);
+ cso_set_clip(ctx->cso, &ctx->clip);
/* sampler */
ctx->sampler.min_img_filter = filter;
@@ -559,6 +577,17 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
+ /* viewport */
+ ctx->viewport.scale[0] = 0.5f * dst->width;
+ ctx->viewport.scale[1] = 0.5f * dst->height;
+ ctx->viewport.scale[2] = 0.5f;
+ ctx->viewport.scale[3] = 1.0f;
+ ctx->viewport.translate[0] = 0.5f * dst->width;
+ ctx->viewport.translate[1] = 0.5f * dst->height;
+ ctx->viewport.translate[2] = 0.5f;
+ ctx->viewport.translate[3] = 0.0f;
+ cso_set_viewport(ctx->cso, &ctx->viewport);
+
/* texture */
cso_set_sampler_textures(ctx->cso, 1, &tex);
@@ -576,8 +605,10 @@ util_blit_pixels_tex(struct blit_state *ctx,
/* draw quad */
offset = setup_vertex_data_tex(ctx,
- (float) dstX0, (float) dstY0,
- (float) dstX1, (float) dstY1,
+ (float) dstX0 / dst->width * 2.0f - 1.0f,
+ (float) dstY0 / dst->height * 2.0f - 1.0f,
+ (float) dstX1 / dst->width * 2.0f - 1.0f,
+ (float) dstY1 / dst->height * 2.0f - 1.0f,
s0, t0, s1, t1,
z);
@@ -596,4 +627,5 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);
cso_restore_vertex_shader(ctx->cso);
+ cso_restore_clip(ctx->cso);
}
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 18f8606818..0ba09d33bf 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -93,6 +93,12 @@ struct blitter_context_priv
/* Rasterizer state. */
void *rs_state;
+
+ /* Viewport state. */
+ struct pipe_viewport_state viewport;
+
+ /* Clip state. */
+ struct pipe_clip_state clip;
};
struct blitter_context *util_blitter_create(struct pipe_context *pipe)
@@ -160,7 +166,6 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
memset(&rs_state, 0, sizeof(rs_state));
rs_state.front_winding = PIPE_WINDING_CW;
rs_state.cull_mode = PIPE_WINDING_NONE;
- rs_state.bypass_vs_clip_and_viewport = 1;
rs_state.gl_rasterization_rules = 1;
rs_state.flatshade = 1;
ctx->rs_state = pipe->create_rasterizer_state(pipe, &rs_state);
@@ -263,6 +268,9 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
pipe->set_stencil_ref(pipe, &ctx->blitter.saved_stencil_ref);
+ pipe->set_viewport_state(pipe, &ctx->blitter.saved_viewport);
+ pipe->set_clip_state(pipe, &ctx->blitter.saved_clip);
+
/* restore the state objects which are required to be saved before copy/fill
*/
if (ctx->blitter.saved_fb_state.nr_cbufs != ~0) {
@@ -288,25 +296,40 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
static void blitter_set_rectangle(struct blitter_context_priv *ctx,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2,
+ unsigned width, unsigned height,
float depth)
{
int i;
/* set vertex positions */
- ctx->vertices[0][0][0] = x1; /*v0.x*/
- ctx->vertices[0][0][1] = y1; /*v0.y*/
+ ctx->vertices[0][0][0] = (float)x1 / width * 2.0f - 1.0f; /*v0.x*/
+ ctx->vertices[0][0][1] = (float)y1 / height * 2.0f - 1.0f; /*v0.y*/
- ctx->vertices[1][0][0] = x2; /*v1.x*/
- ctx->vertices[1][0][1] = y1; /*v1.y*/
+ ctx->vertices[1][0][0] = (float)x2 / width * 2.0f - 1.0f; /*v1.x*/
+ ctx->vertices[1][0][1] = (float)y1 / height * 2.0f - 1.0f; /*v1.y*/
- ctx->vertices[2][0][0] = x2; /*v2.x*/
- ctx->vertices[2][0][1] = y2; /*v2.y*/
+ ctx->vertices[2][0][0] = (float)x2 / width * 2.0f - 1.0f; /*v2.x*/
+ ctx->vertices[2][0][1] = (float)y2 / height * 2.0f - 1.0f; /*v2.y*/
- ctx->vertices[3][0][0] = x1; /*v3.x*/
- ctx->vertices[3][0][1] = y2; /*v3.y*/
+ ctx->vertices[3][0][0] = (float)x1 / width * 2.0f - 1.0f; /*v3.x*/
+ ctx->vertices[3][0][1] = (float)y2 / height * 2.0f - 1.0f; /*v3.y*/
for (i = 0; i < 4; i++)
ctx->vertices[i][0][2] = depth; /*z*/
+
+ /* viewport */
+ ctx->viewport.scale[0] = 0.5f * width;
+ ctx->viewport.scale[1] = 0.5f * height;
+ ctx->viewport.scale[2] = 1.0f;
+ ctx->viewport.scale[3] = 1.0f;
+ ctx->viewport.translate[0] = 0.5f * width;
+ ctx->viewport.translate[1] = 0.5f * height;
+ ctx->viewport.translate[2] = 0.0f;
+ ctx->viewport.translate[3] = 0.0f;
+ ctx->pipe->set_viewport_state(ctx->pipe, &ctx->viewport);
+
+ /* clip */
+ ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip);
}
static void blitter_set_clear_color(struct blitter_context_priv *ctx,
@@ -550,7 +573,7 @@ void util_blitter_clear(struct blitter_context *blitter,
pipe->bind_vs_state(pipe, ctx->vs_col);
blitter_set_clear_color(ctx, rgba);
- blitter_set_rectangle(ctx, 0, 0, width, height, depth);
+ blitter_set_rectangle(ctx, 0, 0, width, height, width, height, depth);
blitter_draw_quad(ctx);
blitter_restore_CSOs(ctx);
}
@@ -633,7 +656,7 @@ static void util_blitter_do_copy(struct blitter_context *blitter,
assert(0);
}
- blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0);
+ blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, dst->width, dst->height, 0);
blitter_draw_quad(ctx);
}
@@ -794,7 +817,7 @@ void util_blitter_fill(struct blitter_context *blitter,
pipe->set_framebuffer_state(pipe, &fb_state);
blitter_set_clear_color(ctx, rgba);
- blitter_set_rectangle(ctx, 0, 0, width, height, 0);
+ blitter_set_rectangle(ctx, 0, 0, width, height, dst->width, dst->height, 0);
blitter_draw_quad(ctx);
blitter_restore_CSOs(ctx);
}
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index a2f17073ac..92008fce99 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -48,6 +48,8 @@ struct blitter_context
struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */
struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */
+ struct pipe_viewport_state saved_viewport;
+ struct pipe_clip_state saved_clip;
int saved_num_sampler_states;
void *saved_sampler_states[32];
@@ -206,6 +208,20 @@ void util_blitter_save_framebuffer(struct blitter_context *blitter,
}
static INLINE
+void util_blitter_save_viewport(struct blitter_context *blitter,
+ struct pipe_viewport_state *state)
+{
+ blitter->saved_viewport = *state;
+}
+
+static INLINE
+void util_blitter_save_clip(struct blitter_context *blitter,
+ struct pipe_clip_state *state)
+{
+ blitter->saved_clip = *state;
+}
+
+static INLINE
void util_blitter_save_fragment_sampler_states(
struct blitter_context *blitter,
int num_sampler_states,
diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c
index eaf4ec90f2..ae7afd7311 100644
--- a/src/gallium/auxiliary/util/u_dump_state.c
+++ b/src/gallium/auxiliary/util/u_dump_state.c
@@ -318,7 +318,6 @@ util_dump_rasterizer_state(struct os_stream *stream, const struct pipe_rasterize
util_dump_member(stream, uint, state, line_stipple_factor);
util_dump_member(stream, uint, state, line_stipple_pattern);
util_dump_member(stream, bool, state, line_last_pixel);
- util_dump_member(stream, bool, state, bypass_vs_clip_and_viewport);
util_dump_member(stream, bool, state, flatshade_first);
util_dump_member(stream, bool, state, gl_rasterization_rules);
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 1d7329d422..f423882ca2 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -61,6 +61,7 @@ struct gen_mipmap_state
struct pipe_depth_stencil_alpha_state depthstencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
+ struct pipe_clip_state clip;
void *vs;
void *fs2d, *fsCube;
@@ -1296,7 +1297,6 @@ util_create_gen_mipmap(struct pipe_context *pipe,
memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
ctx->rasterizer.front_winding = PIPE_WINDING_CW;
ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
- ctx->rasterizer.bypass_vs_clip_and_viewport = 1;
ctx->rasterizer.gl_rasterization_rules = 1;
/* sampler state */
@@ -1361,25 +1361,25 @@ get_next_slot(struct gen_mipmap_state *ctx)
static unsigned
set_vertex_data(struct gen_mipmap_state *ctx,
enum pipe_texture_target tex_target,
- uint face, float width, float height)
+ uint face)
{
unsigned offset;
/* vert[0].position */
- ctx->vertices[0][0][0] = 0.0f; /*x*/
- ctx->vertices[0][0][1] = 0.0f; /*y*/
+ ctx->vertices[0][0][0] = -1.0f; /*x*/
+ ctx->vertices[0][0][1] = -1.0f; /*y*/
/* vert[1].position */
- ctx->vertices[1][0][0] = width;
- ctx->vertices[1][0][1] = 0.0f;
+ ctx->vertices[1][0][0] = 1.0f;
+ ctx->vertices[1][0][1] = -1.0f;
/* vert[2].position */
- ctx->vertices[2][0][0] = width;
- ctx->vertices[2][0][1] = height;
+ ctx->vertices[2][0][0] = 1.0f;
+ ctx->vertices[2][0][1] = 1.0f;
/* vert[3].position */
- ctx->vertices[3][0][0] = 0.0f;
- ctx->vertices[3][0][1] = height;
+ ctx->vertices[3][0][0] = -1.0f;
+ ctx->vertices[3][0][1] = 1.0f;
/* Setup vertex texcoords. This is a little tricky for cube maps. */
if (tex_target == PIPE_TEXTURE_CUBE) {
@@ -1499,11 +1499,14 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
cso_save_framebuffer(ctx->cso);
cso_save_fragment_shader(ctx->cso);
cso_save_vertex_shader(ctx->cso);
+ cso_save_viewport(ctx->cso);
+ cso_save_clip(ctx->cso);
/* bind our state */
cso_set_blend(ctx->cso, &ctx->blend);
cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
+ cso_set_clip(ctx->cso, &ctx->clip);
cso_set_fragment_shader_handle(ctx->cso, fs);
cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
@@ -1522,6 +1525,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
*/
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
+ struct pipe_viewport_state vp;
struct pipe_surface *surf =
screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
@@ -1535,6 +1539,17 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
fb.height = u_minify(pt->height0, dstLevel);
cso_set_framebuffer(ctx->cso, &fb);
+ /* viewport */
+ vp.scale[0] = 0.5f * fb.width;
+ vp.scale[1] = 0.5f * fb.height;
+ vp.scale[2] = 1.0f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * fb.width;
+ vp.translate[1] = 0.5f * fb.height;
+ vp.translate[2] = 0.0f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(ctx->cso, &vp);
+
/*
* Setup sampler state
* Note: we should only have to set the min/max LOD clamps to ensure
@@ -1549,12 +1564,10 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
cso_set_sampler_textures(ctx->cso, 1, &pt);
- /* quad coords in window coords (bypassing vs, clip and viewport) */
+ /* quad coords in clip coords */
offset = set_vertex_data(ctx,
pt->target,
- face,
- (float) u_minify(pt->width0, dstLevel),
- (float) u_minify(pt->height0, dstLevel));
+ face);
util_draw_vertex_buffer(ctx->pipe,
ctx->vbuf,
@@ -1578,4 +1591,6 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);
cso_restore_vertex_shader(ctx->cso);
+ cso_restore_viewport(ctx->cso);
+ cso_restore_clip(ctx->cso);
}