From: Roland Scheidegger Date: Tue, 9 Mar 2010 14:59:40 +0000 (+0100) Subject: Merge branch 'gallium-vertexelementcso' X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=685340a53e1dcb2a888e634ee71ba24356befe69;p=mesa.git Merge branch 'gallium-vertexelementcso' Conflicts: src/gallium/auxiliary/cso_cache/cso_context.c src/gallium/auxiliary/util/u_blit.c src/gallium/auxiliary/util/u_gen_mipmap.c src/gallium/drivers/i915/i915_context.h src/gallium/drivers/i965/brw_draw_upload.c src/gallium/drivers/r300/r300_blit.c src/gallium/drivers/r300/r300_context.h src/gallium/drivers/r300/r300_render.c src/gallium/drivers/r300/r300_state_derived.c src/mesa/state_tracker/st_cb_bitmap.c src/mesa/state_tracker/st_cb_clear.c --- 685340a53e1dcb2a888e634ee71ba24356befe69 diff --cc src/gallium/auxiliary/cso_cache/cso_context.c index a7335c340ca,510366a8d47..292e489312b --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@@ -89,10 -89,8 +89,11 @@@ struct cso_context void *rasterizer, *rasterizer_saved; void *fragment_shader, *fragment_shader_saved, *geometry_shader; void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved; + void *velements, *velements_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; @@@ -1130,53 -1145,65 +1148,115 @@@ void cso_restore_geometry_shader(struc 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); + } +} ++ + enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, + unsigned count, + const struct pipe_vertex_element *states) + { + unsigned key_size, hash_key; + struct cso_hash_iter iter; + void *handle; + struct cso_velems_state velems_state; + + /* need to include the count into the stored state data too. + Otherwise first few count pipe_vertex_elements could be identical even if count + is different, and there's no guarantee the hash would be different in that + case neither */ + key_size = sizeof(struct pipe_vertex_element) * count + sizeof(unsigned); + velems_state.count = count; + memcpy(velems_state.velems, states, sizeof(struct pipe_vertex_element) * count); + hash_key = cso_construct_key((void*)&velems_state, key_size); + iter = cso_find_state_template(ctx->cache, hash_key, CSO_VELEMENTS, (void*)&velems_state, key_size); + + if (cso_hash_iter_is_null(iter)) { + struct cso_velements *cso = MALLOC(sizeof(struct cso_velements)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, &velems_state, key_size); + cso->data = ctx->pipe->create_vertex_elements_state(ctx->pipe, count, &cso->state.velems[0]); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_vertex_elements_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_VELEMENTS, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_velements *)cso_hash_iter_data(iter))->data; + } + + if (ctx->velements != handle) { + ctx->velements = handle; + ctx->pipe->bind_vertex_elements_state(ctx->pipe, handle); + } + return PIPE_OK; + } + + void cso_save_vertex_elements(struct cso_context *ctx) + { + assert(!ctx->velements); + ctx->velements_saved = ctx->velements; + } + + void cso_restore_vertex_elements(struct cso_context *ctx) + { + if (ctx->velements != ctx->velements_saved) { + ctx->velements = ctx->velements_saved; + ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->velements_saved); + } + ctx->velements_saved = NULL; -} ++} diff --cc src/gallium/auxiliary/util/u_blit.c index 0b263a9db5c,0d93e23df86..4d0737ccd3d --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@@ -62,7 -62,7 +62,8 @@@ struct blit_stat struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_viewport_state viewport; + struct pipe_clip_state clip; + struct pipe_vertex_element velem[2]; void *vs; void *fs[TGSI_WRITEMASK_XYZW + 1]; @@@ -114,6 -115,16 +115,15 @@@ util_create_blit(struct pipe_context *p ctx->sampler.mag_img_filter = 0; /* set later */ ctx->sampler.normalized_coords = 1; - + /* vertex elements state */ + memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2); + for (i = 0; i < 2; i++) { + ctx->velem[i].src_offset = i * 4 * sizeof(float); + ctx->velem[i].instance_divisor = 0; + ctx->velem[i].vertex_buffer_index = 0; + ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + /* vertex shader - still required to provide the linkage between * fragment shader input semantics and vertex_element/buffers. */ @@@ -409,13 -420,13 +419,15 @@@ util_blit_pixels_writemask(struct blit_ cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); + cso_save_vertex_elements(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); + cso_set_vertex_elements(ctx->cso, 2, ctx->velem); /* sampler */ ctx->sampler.min_img_filter = filter; @@@ -479,7 -476,7 +491,8 @@@ cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); + cso_restore_vertex_elements(ctx->cso); pipe_texture_reference(&tex, NULL); } @@@ -563,13 -560,13 +576,15 @@@ util_blit_pixels_tex(struct blit_state cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); + cso_save_vertex_elements(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); + cso_set_vertex_elements(ctx->cso, 2, ctx->velem); /* sampler */ ctx->sampler.min_img_filter = filter; @@@ -627,5 -611,5 +642,6 @@@ cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); + cso_restore_vertex_elements(ctx->cso); } diff --cc src/gallium/auxiliary/util/u_gen_mipmap.c index fc027e48e4e,db726df9c3b..d421bee8efe --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@@ -61,7 -61,7 +61,8 @@@ struct gen_mipmap_stat struct pipe_depth_stencil_alpha_state depthstencil; struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; + struct pipe_clip_state clip; + struct pipe_vertex_element velem[2]; void *vs; void *fs2d, *fsCube; @@@ -1499,14 -1509,13 +1509,16 @@@ util_gen_mipmap(struct gen_mipmap_stat 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); + cso_save_vertex_elements(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_vertex_elements(ctx->cso, 2, ctx->velem); cso_set_fragment_shader_handle(ctx->cso, fs); cso_set_vertex_shader_handle(ctx->cso, ctx->vs); @@@ -1591,6 -1590,5 +1603,7 @@@ 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); + cso_restore_vertex_elements(ctx->cso); } diff --cc src/gallium/drivers/i915/i915_context.h index 499a727314d,3e383aaa1ca..49945376837 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@@ -187,9 -187,11 +187,14 @@@ struct i915_sampler_state unsigned maxlod; }; + struct i915_velems_state { + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; + }; + +#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + struct i915_texture { struct pipe_texture base; diff --cc src/gallium/drivers/r300/r300_blit.c index 513cc0f5d44,297768e5cf4..b7ad6b20206 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@@ -33,9 -33,8 +33,10 @@@ static void r300_blitter_save_states(st util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref)); util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state); util_blitter_save_fragment_shader(r300->blitter, r300->fs); - util_blitter_save_vertex_shader(r300->blitter, r300->vs); + util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state); + util_blitter_save_viewport(r300->blitter, &r300->viewport); + util_blitter_save_clip(r300->blitter, &r300->clip); + util_blitter_save_vertex_elements(r300->blitter, r300->velems); } /* Clear currently bound buffers. */ diff --cc src/gallium/drivers/r300/r300_context.h index c2825d5f267,f372743c5b8..80e69924f08 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@@ -348,20 -321,11 +363,19 @@@ struct r300_context /* Vertex buffers for Gallium. */ struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; int vertex_buffer_count; + int vertex_buffer_max_index; /* Vertex elements for Gallium. */ - struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; - int vertex_element_count; + struct r300_velems_state *velems; + /* Vertex info for Draw. */ + struct vertex_info vertex_info; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + + struct pipe_viewport_state viewport; + /* Bitmask of dirty state objects. */ uint32_t dirty_state; /* Flag indicating whether or not the HW is dirty. */ diff --cc src/gallium/drivers/r300/r300_render.c index c8420bcdd5b,1850a6f247a..d0e06ade40f --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@@ -143,8 -128,8 +143,8 @@@ static void r300_emit_draw_arrays_immed { struct pipe_vertex_element* velem; struct pipe_vertex_buffer* vbuf; - unsigned vertex_element_count = r300->vertex_element_count; + unsigned vertex_element_count = r300->velems->count; - unsigned i, v, vbi, dw, elem_offset; + unsigned i, v, vbi, dw, elem_offset, dwords; /* Size of the vertex, in dwords. */ unsigned vertex_size = 0; diff --cc src/gallium/drivers/r300/r300_state_derived.c index e9e40747ef1,c43a93601cb..4422581b514 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@@ -126,11 -127,11 +126,12 @@@ static void r300_vertex_psc(struct r300 * and not on attrib information. */ DBG(r300, DBG_DRAW, "r300: vs expects %d attribs, routing %d elements" " in psc\n", - r300->vs->info.num_inputs, + vs->info.num_inputs, + r300->velems->count); + r300->vertex_element_count); - for (i = 0; i < r300->vertex_element_count; i++) { - format = r300->vertex_element[i].src_format; + for (i = 0; i < r300->velems->count; i++) { + format = r300->velems->velem[i].src_format; type = r300_translate_vertex_data_type(format) | (stream_tab[i] << R300_DST_VEC_LOC_SHIFT); diff --cc src/gallium/include/pipe/p_state.h index 72635d1031b,5670f7a0887..3a97d888ce6 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@@ -373,9 -383,8 +373,8 @@@ struct pipe_vertex_elemen * this attribute live in? */ unsigned vertex_buffer_index:8; - unsigned nr_components:8; - enum pipe_format src_format; /**< PIPE_FORMAT_* */ + enum pipe_format src_format; }; diff --cc src/mesa/state_tracker/st_cb_bitmap.c index 0332d4dbdfe,95b148a7b45..f326601c3be --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@@ -490,9 -491,8 +491,11 @@@ draw_bitmap_quad(GLcontext *ctx, GLint cso_set_viewport(cso, &vp); } + cso_set_vertex_elements(cso, 3, st->velems_util_draw); + + /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */ + z = z * 2.0 - 1.0; + /* draw textured quad */ offset = setup_bitmap_vertex_data(st, x, y, width, height, z, color); diff --cc src/mesa/state_tracker/st_cb_clear.c index 9e66eed3634,efba9853b46..de86062fc40 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@@ -209,10 -218,9 +209,11 @@@ clear_with_quad(GLcontext *ctx cso_save_stencil_ref(st->cso_context); cso_save_depth_stencil_alpha(st->cso_context); cso_save_rasterizer(st->cso_context); + cso_save_viewport(st->cso_context); + cso_save_clip(st->cso_context); cso_save_fragment_shader(st->cso_context); cso_save_vertex_shader(st->cso_context); + cso_save_vertex_elements(st->cso_context); /* blend state: RGBA masking */ { @@@ -264,24 -272,10 +265,26 @@@ cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); } + cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw); + cso_set_rasterizer(st->cso_context, &st->clear.raster); + /* viewport state: viewport matching window dims */ + { + const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); + struct pipe_viewport_state vp; + vp.scale[0] = 0.5f * fb_width; + vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f); + 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(st->cso_context, &vp); + } + + cso_set_clip(st->cso_context, &st->clear.clip); cso_set_fragment_shader_handle(st->cso_context, st->clear.fs); cso_set_vertex_shader_handle(st->cso_context, st->clear.vs); @@@ -293,10 -287,10 +296,12 @@@ cso_restore_stencil_ref(st->cso_context); cso_restore_depth_stencil_alpha(st->cso_context); cso_restore_rasterizer(st->cso_context); + cso_restore_viewport(st->cso_context); + cso_restore_clip(st->cso_context); cso_restore_fragment_shader(st->cso_context); cso_restore_vertex_shader(st->cso_context); + cso_restore_vertex_elements(st->cso_context); + }