diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index b09643dcd8a..f2aa7c0d0be 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -123,13 +123,17 @@ struct cso_context { struct cso_cache cache; }; -struct pipe_context *cso_get_pipe_context(struct cso_context *cso) + +struct pipe_context * +cso_get_pipe_context(struct cso_context *cso) { return cso->pipe; } -static inline boolean delete_cso(struct cso_context *ctx, - void *state, enum cso_cache_type type) + +static inline boolean +delete_cso(struct cso_context *ctx, + void *state, enum cso_cache_type type) { switch (type) { case CSO_BLEND: @@ -159,6 +163,7 @@ static inline boolean delete_cso(struct cso_context *ctx, return true; } + static inline void sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, int max_size, void *user_data) @@ -166,10 +171,9 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, struct cso_context *ctx = (struct cso_context *)user_data; /* if we're approach the maximum size, remove fourth of the entries * otherwise every subsequent call will go through the same */ - int hash_size = cso_hash_size(hash); - int max_entries = (max_size > hash_size) ? max_size : hash_size; + const int hash_size = cso_hash_size(hash); + const int max_entries = (max_size > hash_size) ? max_size : hash_size; int to_remove = (max_size < max_entries) * max_entries/4; - struct cso_hash_iter iter; struct cso_sampler **samplers_to_restore = NULL; unsigned to_restore = 0; @@ -180,16 +184,14 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, return; if (type == CSO_SAMPLER) { - int i, j; - samplers_to_restore = MALLOC(PIPE_SHADER_TYPES * PIPE_MAX_SAMPLERS * sizeof(*samplers_to_restore)); /* Temporarily remove currently bound sampler states from the hash * table, to prevent them from being deleted */ - for (i = 0; i < PIPE_SHADER_TYPES; i++) { - for (j = 0; j < PIPE_MAX_SAMPLERS; j++) { + for (int i = 0; i < PIPE_SHADER_TYPES; i++) { + for (int j = 0; j < PIPE_MAX_SAMPLERS; j++) { struct cso_sampler *sampler = ctx->samplers[i].cso_samplers[j]; if (sampler && cso_hash_take(hash, sampler->hash_key)) @@ -198,7 +200,7 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, } } - iter = cso_hash_first_node(hash); + struct cso_hash_iter iter = cso_hash_first_node(hash); while (to_remove) { /*remove elements until we're good */ /*fixme: currently we pick the nodes to remove at random*/ @@ -210,8 +212,9 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, if (delete_cso(ctx, cso, type)) { iter = cso_hash_erase(hash, iter); --to_remove; - } else + } else { iter = cso_hash_iter_next(iter); + } } if (type == CSO_SAMPLER) { @@ -226,7 +229,9 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, } } -static void cso_init_vbuf(struct cso_context *cso, unsigned flags) + +static void +cso_init_vbuf(struct cso_context *cso, unsigned flags) { struct u_vbuf_caps caps; bool uses_user_vertex_buffers = !(flags & CSO_NO_USER_VERTEX_BUFFERS); @@ -244,6 +249,7 @@ static void cso_init_vbuf(struct cso_context *cso, unsigned flags) } } + struct cso_context * cso_create_context(struct pipe_context *pipe, unsigned flags) { @@ -286,18 +292,22 @@ cso_create_context(struct pipe_context *pipe, unsigned flags) ctx->has_streamout = TRUE; } - if (pipe->screen->get_param(pipe->screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & + if (pipe->screen->get_param(pipe->screen, + PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO) ctx->sampler_format = true; - ctx->max_fs_samplerviews = pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_FRAGMENT, - PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS); + ctx->max_fs_samplerviews = + pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_FRAGMENT, + PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS); ctx->max_sampler_seen = -1; return ctx; } -void cso_unbind_context(struct cso_context *ctx) + +void +cso_unbind_context(struct cso_context *ctx) { unsigned i; @@ -305,8 +315,8 @@ void cso_unbind_context(struct cso_context *ctx) if (dumping) trace_dumping_stop_locked(); if (ctx->pipe) { - ctx->pipe->bind_blend_state( ctx->pipe, NULL ); - ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL ); + ctx->pipe->bind_blend_state(ctx->pipe, NULL); + ctx->pipe->bind_rasterizer_state(ctx->pipe, NULL); { static struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS] = { NULL }; @@ -366,12 +376,12 @@ void cso_unbind_context(struct cso_context *ctx) } } - ctx->pipe->bind_depth_stencil_alpha_state( ctx->pipe, NULL ); + ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, NULL); struct pipe_stencil_ref sr = {0}; ctx->pipe->set_stencil_ref(ctx->pipe, sr); - ctx->pipe->bind_fs_state( ctx->pipe, NULL ); + ctx->pipe->bind_fs_state(ctx->pipe, NULL); ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, false, NULL); - ctx->pipe->bind_vs_state( ctx->pipe, NULL ); + ctx->pipe->bind_vs_state(ctx->pipe, NULL); ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_VERTEX, 0, false, NULL); if (ctx->has_geometry_shader) { ctx->pipe->bind_gs_state(ctx->pipe, NULL); @@ -383,7 +393,7 @@ void cso_unbind_context(struct cso_context *ctx) if (ctx->has_compute_shader) { ctx->pipe->bind_compute_state(ctx->pipe, NULL); } - ctx->pipe->bind_vertex_elements_state( ctx->pipe, NULL ); + ctx->pipe->bind_vertex_elements_state(ctx->pipe, NULL); if (ctx->has_streamout) ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, NULL); @@ -398,7 +408,9 @@ void cso_unbind_context(struct cso_context *ctx) } memset(&ctx->samplers, 0, sizeof(ctx->samplers)); - memset(&ctx->nr_so_targets, 0, offsetof(struct cso_context, cache) - offsetof(struct cso_context, nr_so_targets)); + memset(&ctx->nr_so_targets, 0, + offsetof(struct cso_context, cache) + - offsetof(struct cso_context, nr_so_targets)); ctx->sample_mask = ~0; /* * If the cso context is reused (with the same pipe context), @@ -411,17 +423,19 @@ void cso_unbind_context(struct cso_context *ctx) trace_dumping_start_locked(); } + /** * Free the CSO context. */ -void cso_destroy_context( struct cso_context *ctx ) +void +cso_destroy_context(struct cso_context *ctx) { cso_unbind_context(ctx); cso_cache_delete(&ctx->cache); if (ctx->vbuf) u_vbuf_destroy(ctx->vbuf); - FREE( ctx ); + FREE(ctx); } @@ -435,19 +449,18 @@ void cso_destroy_context( struct cso_context *ctx ) * the data member of the cso to be the template itself. */ -enum pipe_error cso_set_blend(struct cso_context *ctx, - const struct pipe_blend_state *templ) +enum pipe_error +cso_set_blend(struct cso_context *ctx, + const struct pipe_blend_state *templ) { - unsigned key_size, hash_key; - struct cso_hash_iter iter; - void *handle; - - key_size = templ->independent_blend_enable ? + const unsigned key_size = templ->independent_blend_enable ? sizeof(struct pipe_blend_state) : (char *)&(templ->rt[1]) - (char *)templ; - hash_key = cso_construct_key((void*)templ, key_size); - iter = cso_find_state_template(&ctx->cache, hash_key, CSO_BLEND, - (void*)templ, key_size); + const unsigned hash_key = cso_construct_key((void*)templ, key_size); + struct cso_hash_iter iter = + cso_find_state_template(&ctx->cache, hash_key, CSO_BLEND, + (void*)templ, key_size); + void *handle; if (cso_hash_iter_is_null(iter)) { struct cso_blend *cso = MALLOC(sizeof(struct cso_blend)); @@ -465,8 +478,7 @@ enum pipe_error cso_set_blend(struct cso_context *ctx, } handle = cso->data; - } - else { + } else { handle = ((struct cso_blend *)cso_hash_iter_data(iter))->data; } @@ -477,6 +489,7 @@ enum pipe_error cso_set_blend(struct cso_context *ctx, return PIPE_OK; } + static void cso_save_blend(struct cso_context *ctx) { @@ -484,6 +497,7 @@ cso_save_blend(struct cso_context *ctx) ctx->blend_saved = ctx->blend; } + static void cso_restore_blend(struct cso_context *ctx) { @@ -495,13 +509,12 @@ cso_restore_blend(struct cso_context *ctx) } - enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx, const struct pipe_depth_stencil_alpha_state *templ) { - unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state); - unsigned hash_key = cso_construct_key((void*)templ, key_size); + const unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state); + const unsigned hash_key = cso_construct_key((void*)templ, key_size); struct cso_hash_iter iter = cso_find_state_template(&ctx->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, @@ -526,8 +539,7 @@ cso_set_depth_stencil_alpha(struct cso_context *ctx, } handle = cso->data; - } - else { + } else { handle = ((struct cso_depth_stencil_alpha *) cso_hash_iter_data(iter))->data; } @@ -539,6 +551,7 @@ cso_set_depth_stencil_alpha(struct cso_context *ctx, return PIPE_OK; } + static void cso_save_depth_stencil_alpha(struct cso_context *ctx) { @@ -546,6 +559,7 @@ cso_save_depth_stencil_alpha(struct cso_context *ctx) ctx->depth_stencil_saved = ctx->depth_stencil; } + static void cso_restore_depth_stencil_alpha(struct cso_context *ctx) { @@ -558,12 +572,12 @@ cso_restore_depth_stencil_alpha(struct cso_context *ctx) } - -enum pipe_error cso_set_rasterizer(struct cso_context *ctx, - const struct pipe_rasterizer_state *templ) +enum pipe_error +cso_set_rasterizer(struct cso_context *ctx, + const struct pipe_rasterizer_state *templ) { - unsigned key_size = sizeof(struct pipe_rasterizer_state); - unsigned hash_key = cso_construct_key((void*)templ, key_size); + const unsigned key_size = sizeof(struct pipe_rasterizer_state); + const unsigned hash_key = cso_construct_key((void*)templ, key_size); struct cso_hash_iter iter = cso_find_state_template(&ctx->cache, hash_key, CSO_RASTERIZER, @@ -590,8 +604,7 @@ enum pipe_error cso_set_rasterizer(struct cso_context *ctx, } handle = cso->data; - } - else { + } else { handle = ((struct cso_rasterizer *)cso_hash_iter_data(iter))->data; } @@ -605,6 +618,7 @@ enum pipe_error cso_set_rasterizer(struct cso_context *ctx, return PIPE_OK; } + static void cso_save_rasterizer(struct cso_context *ctx) { @@ -613,6 +627,7 @@ cso_save_rasterizer(struct cso_context *ctx) ctx->flatshade_first_saved = ctx->flatshade_first; } + static void cso_restore_rasterizer(struct cso_context *ctx) { @@ -627,7 +642,8 @@ cso_restore_rasterizer(struct cso_context *ctx) } -void cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle ) +void +cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle) { if (ctx->fragment_shader != handle) { ctx->fragment_shader = handle; @@ -635,6 +651,7 @@ void cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle ) } } + static void cso_save_fragment_shader(struct cso_context *ctx) { @@ -642,6 +659,7 @@ cso_save_fragment_shader(struct cso_context *ctx) ctx->fragment_shader_saved = ctx->fragment_shader; } + static void cso_restore_fragment_shader(struct cso_context *ctx) { @@ -653,7 +671,8 @@ cso_restore_fragment_shader(struct cso_context *ctx) } -void cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle) +void +cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle) { if (ctx->vertex_shader != handle) { ctx->vertex_shader = handle; @@ -661,6 +680,7 @@ void cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle) } } + static void cso_save_vertex_shader(struct cso_context *ctx) { @@ -668,6 +688,7 @@ cso_save_vertex_shader(struct cso_context *ctx) ctx->vertex_shader_saved = ctx->vertex_shader; } + static void cso_restore_vertex_shader(struct cso_context *ctx) { @@ -679,8 +700,9 @@ cso_restore_vertex_shader(struct cso_context *ctx) } -void cso_set_framebuffer(struct cso_context *ctx, - const struct pipe_framebuffer_state *fb) +void +cso_set_framebuffer(struct cso_context *ctx, + const struct pipe_framebuffer_state *fb) { if (memcmp(&ctx->fb, fb, sizeof(*fb)) != 0) { util_copy_framebuffer_state(&ctx->fb, fb); @@ -688,12 +710,14 @@ void cso_set_framebuffer(struct cso_context *ctx, } } + static void cso_save_framebuffer(struct cso_context *ctx) { util_copy_framebuffer_state(&ctx->fb_saved, &ctx->fb); } + static void cso_restore_framebuffer(struct cso_context *ctx) { @@ -705,8 +729,9 @@ cso_restore_framebuffer(struct cso_context *ctx) } -void cso_set_viewport(struct cso_context *ctx, - const struct pipe_viewport_state *vp) +void +cso_set_viewport(struct cso_context *ctx, + const struct pipe_viewport_state *vp) { if (memcmp(&ctx->vp, vp, sizeof(*vp))) { ctx->vp = *vp; @@ -714,6 +739,7 @@ void cso_set_viewport(struct cso_context *ctx, } } + /** * Setup viewport state for given width and height (position is always (0,0)). * Invert the Y axis if 'invert' is true. @@ -736,6 +762,7 @@ cso_set_viewport_dims(struct cso_context *ctx, cso_set_viewport(ctx, &vp); } + static void cso_save_viewport(struct cso_context *ctx) { @@ -752,7 +779,9 @@ cso_restore_viewport(struct cso_context *ctx) } } -void cso_set_sample_mask(struct cso_context *ctx, unsigned sample_mask) + +void +cso_set_sample_mask(struct cso_context *ctx, unsigned sample_mask) { if (ctx->sample_mask != sample_mask) { ctx->sample_mask = sample_mask; @@ -760,19 +789,23 @@ void cso_set_sample_mask(struct cso_context *ctx, unsigned sample_mask) } } + static void cso_save_sample_mask(struct cso_context *ctx) { ctx->sample_mask_saved = ctx->sample_mask; } + static void cso_restore_sample_mask(struct cso_context *ctx) { cso_set_sample_mask(ctx, ctx->sample_mask_saved); } -void cso_set_min_samples(struct cso_context *ctx, unsigned min_samples) + +void +cso_set_min_samples(struct cso_context *ctx, unsigned min_samples) { if (ctx->min_samples != min_samples && ctx->pipe->set_min_samples) { ctx->min_samples = min_samples; @@ -780,20 +813,24 @@ void cso_set_min_samples(struct cso_context *ctx, unsigned min_samples) } } + static void cso_save_min_samples(struct cso_context *ctx) { ctx->min_samples_saved = ctx->min_samples; } + static void cso_restore_min_samples(struct cso_context *ctx) { cso_set_min_samples(ctx, ctx->min_samples_saved); } -void cso_set_stencil_ref(struct cso_context *ctx, - const struct pipe_stencil_ref sr) + +void +cso_set_stencil_ref(struct cso_context *ctx, + const struct pipe_stencil_ref sr) { if (memcmp(&ctx->stencil_ref, &sr, sizeof(ctx->stencil_ref))) { ctx->stencil_ref = sr; @@ -801,6 +838,7 @@ void cso_set_stencil_ref(struct cso_context *ctx, } } + static void cso_save_stencil_ref(struct cso_context *ctx) { @@ -818,10 +856,12 @@ cso_restore_stencil_ref(struct cso_context *ctx) } } -void cso_set_render_condition(struct cso_context *ctx, - struct pipe_query *query, - boolean condition, - enum pipe_render_cond_flag mode) + +void +cso_set_render_condition(struct cso_context *ctx, + struct pipe_query *query, + boolean condition, + enum pipe_render_cond_flag mode) { struct pipe_context *pipe = ctx->pipe; @@ -835,6 +875,7 @@ void cso_set_render_condition(struct cso_context *ctx, } } + static void cso_save_render_condition(struct cso_context *ctx) { @@ -843,6 +884,7 @@ cso_save_render_condition(struct cso_context *ctx) ctx->render_condition_mode_saved = ctx->render_condition_mode; } + static void cso_restore_render_condition(struct cso_context *ctx) { @@ -851,7 +893,9 @@ cso_restore_render_condition(struct cso_context *ctx) ctx->render_condition_mode_saved); } -void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle) + +void +cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle) { assert(ctx->has_geometry_shader || !handle); @@ -861,6 +905,7 @@ void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle) } } + static void cso_save_geometry_shader(struct cso_context *ctx) { @@ -872,6 +917,7 @@ cso_save_geometry_shader(struct cso_context *ctx) ctx->geometry_shader_saved = ctx->geometry_shader; } + static void cso_restore_geometry_shader(struct cso_context *ctx) { @@ -886,7 +932,9 @@ cso_restore_geometry_shader(struct cso_context *ctx) ctx->geometry_shader_saved = NULL; } -void cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle) + +void +cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle) { assert(ctx->has_tessellation || !handle); @@ -896,6 +944,7 @@ void cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle) } } + static void cso_save_tessctrl_shader(struct cso_context *ctx) { @@ -907,6 +956,7 @@ cso_save_tessctrl_shader(struct cso_context *ctx) ctx->tessctrl_shader_saved = ctx->tessctrl_shader; } + static void cso_restore_tessctrl_shader(struct cso_context *ctx) { @@ -921,7 +971,9 @@ cso_restore_tessctrl_shader(struct cso_context *ctx) ctx->tessctrl_shader_saved = NULL; } -void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle) + +void +cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle) { assert(ctx->has_tessellation || !handle); @@ -931,6 +983,7 @@ void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle) } } + static void cso_save_tesseval_shader(struct cso_context *ctx) { @@ -942,6 +995,7 @@ cso_save_tesseval_shader(struct cso_context *ctx) ctx->tesseval_shader_saved = ctx->tesseval_shader; } + static void cso_restore_tesseval_shader(struct cso_context *ctx) { @@ -956,7 +1010,9 @@ cso_restore_tesseval_shader(struct cso_context *ctx) ctx->tesseval_shader_saved = NULL; } -void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle) + +void +cso_set_compute_shader_handle(struct cso_context *ctx, void *handle) { assert(ctx->has_compute_shader || !handle); @@ -966,6 +1022,7 @@ void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle) } } + static void cso_save_compute_shader(struct cso_context *ctx) { @@ -977,6 +1034,7 @@ cso_save_compute_shader(struct cso_context *ctx) ctx->compute_shader_saved = ctx->compute_shader; } + static void cso_restore_compute_shader(struct cso_context *ctx) { @@ -1029,20 +1087,18 @@ static void cso_set_vertex_elements_direct(struct cso_context *ctx, const struct cso_velems_state *velems) { - unsigned key_size, hash_key; - struct cso_hash_iter iter; - void *handle; - /* 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) * velems->count + - sizeof(unsigned); - hash_key = cso_construct_key((void*)velems, key_size); - iter = cso_find_state_template(&ctx->cache, hash_key, CSO_VELEMENTS, - (void*)velems, key_size); + const unsigned key_size = + sizeof(struct pipe_vertex_element) * velems->count + sizeof(unsigned); + const unsigned hash_key = cso_construct_key((void*)velems, key_size); + struct cso_hash_iter iter = + cso_find_state_template(&ctx->cache, hash_key, CSO_VELEMENTS, + (void*)velems, key_size); + void *handle; if (cso_hash_iter_is_null(iter)) { struct cso_velements *cso = MALLOC(sizeof(struct cso_velements)); @@ -1067,8 +1123,7 @@ cso_set_vertex_elements_direct(struct cso_context *ctx, } handle = cso->data; - } - else { + } else { handle = ((struct cso_velements *)cso_hash_iter_data(iter))->data; } @@ -1078,6 +1133,7 @@ cso_set_vertex_elements_direct(struct cso_context *ctx, } } + enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, const struct cso_velems_state *velems) @@ -1093,6 +1149,7 @@ cso_set_vertex_elements(struct cso_context *ctx, return PIPE_OK; } + static void cso_save_vertex_elements(struct cso_context *ctx) { @@ -1107,6 +1164,7 @@ cso_save_vertex_elements(struct cso_context *ctx) ctx->velements_saved = ctx->velements; } + static void cso_restore_vertex_elements(struct cso_context *ctx) { @@ -1126,11 +1184,12 @@ cso_restore_vertex_elements(struct cso_context *ctx) /* vertex buffers */ -void cso_set_vertex_buffers(struct cso_context *ctx, - unsigned start_slot, unsigned count, - unsigned unbind_trailing_count, - bool take_ownership, - const struct pipe_vertex_buffer *buffers) +void +cso_set_vertex_buffers(struct cso_context *ctx, + unsigned start_slot, unsigned count, + unsigned unbind_trailing_count, + bool take_ownership, + const struct pipe_vertex_buffer *buffers) { struct u_vbuf *vbuf = ctx->vbuf_current; @@ -1148,6 +1207,7 @@ void cso_set_vertex_buffers(struct cso_context *ctx, take_ownership, buffers); } + /** * Set vertex buffers and vertex elements. Skip u_vbuf if it's only needed * for user vertex buffers and user vertex buffers are not set by this call. @@ -1213,9 +1273,11 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, cso_set_vertex_elements_direct(ctx, velems); } + ALWAYS_INLINE static struct cso_sampler * set_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, - unsigned idx, const struct pipe_sampler_state *templ, size_t key_size) + unsigned idx, const struct pipe_sampler_state *templ, + size_t key_size) { unsigned hash_key = cso_construct_key((void*)templ, key_size); struct cso_sampler *cso; @@ -1244,9 +1306,11 @@ set_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, return cso; } -ALWAYS_INLINE static bool + +ALWAYS_INLINE static bool cso_set_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, - unsigned idx, const struct pipe_sampler_state *templ, size_t size) + unsigned idx, const struct pipe_sampler_state *templ, + size_t size) { struct cso_sampler *cso = set_sampler(ctx, shader_stage, idx, templ, size); ctx->samplers[shader_stage].cso_samplers[idx] = cso; @@ -1254,16 +1318,18 @@ cso_set_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, return true; } + void cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, unsigned idx, const struct pipe_sampler_state *templ) { size_t size = ctx->sampler_format ? sizeof(struct pipe_sampler_state) : - offsetof(struct pipe_sampler_state, border_color_format); + offsetof(struct pipe_sampler_state, border_color_format); if (cso_set_sampler(ctx, shader_stage, idx, templ, size)) ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx); } + /** * Send staged sampler state to the driver. */ @@ -1282,6 +1348,7 @@ cso_single_sampler_done(struct cso_context *ctx, ctx->max_sampler_seen = -1; } + ALWAYS_INLINE static int set_samplers(struct cso_context *ctx, enum pipe_shader_type shader_stage, @@ -1324,6 +1391,7 @@ set_samplers(struct cso_context *ctx, return last; } + /* * If the function encouters any errors it will return the * last one. Done to always try to set as many samplers @@ -1335,17 +1403,16 @@ cso_set_samplers(struct cso_context *ctx, unsigned nr, const struct pipe_sampler_state **templates) { - int last = -1; - /* ensure sampler size is a constant for memcmp */ size_t size = ctx->sampler_format ? sizeof(struct pipe_sampler_state) : - offsetof(struct pipe_sampler_state, border_color_format); - last = set_samplers(ctx, shader_stage, nr, templates, size); + offsetof(struct pipe_sampler_state, border_color_format); + int last = set_samplers(ctx, shader_stage, nr, templates, size); ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, last); cso_single_sampler_done(ctx, shader_stage); } + static void cso_save_fragment_samplers(struct cso_context *ctx) { @@ -1412,23 +1479,23 @@ cso_set_stream_outputs(struct cso_context *ctx, ctx->nr_so_targets = num_targets; } + static void cso_save_stream_outputs(struct cso_context *ctx) { - uint i; - if (!ctx->has_streamout) { return; } ctx->nr_so_targets_saved = ctx->nr_so_targets; - for (i = 0; i < ctx->nr_so_targets; i++) { + for (unsigned i = 0; i < ctx->nr_so_targets; i++) { assert(!ctx->so_targets_saved[i]); pipe_so_target_reference(&ctx->so_targets_saved[i], ctx->so_targets[i]); } } + static void cso_restore_stream_outputs(struct cso_context *ctx) { @@ -1580,6 +1647,7 @@ cso_restore_state(struct cso_context *cso, unsigned unbind) cso->saved_state = 0; } + /** * Save all the CSO state items specified by the state_mask bitmask * of CSO_BIT_COMPUTE_x flags. @@ -1668,6 +1736,7 @@ cso_multi_draw(struct cso_context *cso, } } + void cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count) { @@ -1688,6 +1757,7 @@ cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count) cso_draw_vbo(cso, &info, 0, NULL, draw); } + void cso_draw_arrays_instanced(struct cso_context *cso, uint mode, uint start, uint count, diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 3c5b6064209..4b9ec2098bf 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -46,25 +46,28 @@ struct u_vbuf; #define CSO_NO_64B_VERTEX_BUFFERS (1 << 1) #define CSO_NO_VBUF (1 << 2) -struct cso_context *cso_create_context(struct pipe_context *pipe, - unsigned flags); -void cso_unbind_context(struct cso_context *ctx); -void cso_destroy_context( struct cso_context *cso ); -struct pipe_context *cso_get_pipe_context(struct cso_context *cso); +struct cso_context * +cso_create_context(struct pipe_context *pipe, unsigned flags); +void +cso_unbind_context(struct cso_context *ctx); -enum pipe_error cso_set_blend( struct cso_context *cso, - const struct pipe_blend_state *blend ); +void +cso_destroy_context(struct cso_context *cso); +struct pipe_context * +cso_get_pipe_context(struct cso_context *cso); -enum pipe_error cso_set_depth_stencil_alpha( struct cso_context *cso, - const struct pipe_depth_stencil_alpha_state *dsa ); +enum pipe_error +cso_set_blend(struct cso_context *cso, const struct pipe_blend_state *blend); +enum pipe_error +cso_set_depth_stencil_alpha(struct cso_context *cso, + const struct pipe_depth_stencil_alpha_state *dsa); - -enum pipe_error cso_set_rasterizer( struct cso_context *cso, - const struct pipe_rasterizer_state *rasterizer ); - +enum pipe_error +cso_set_rasterizer(struct cso_context *cso, + const struct pipe_rasterizer_state *rasterizer); void cso_set_samplers(struct cso_context *cso, @@ -85,8 +88,9 @@ cso_single_sampler_done(struct cso_context *cso, enum pipe_shader_type shader_stage); -enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, - const struct cso_velems_state *velems); +enum pipe_error +cso_set_vertex_elements(struct cso_context *ctx, + const struct cso_velems_state *velems); void cso_set_vertex_buffers(struct cso_context *ctx, unsigned start_slot, unsigned count, @@ -124,26 +128,33 @@ void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle); void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle); -void cso_set_framebuffer(struct cso_context *cso, - const struct pipe_framebuffer_state *fb); +void +cso_set_framebuffer(struct cso_context *cso, + const struct pipe_framebuffer_state *fb); +void +cso_set_viewport(struct cso_context *cso, + const struct pipe_viewport_state *vp); -void cso_set_viewport(struct cso_context *cso, - const struct pipe_viewport_state *vp); -void cso_set_viewport_dims(struct cso_context *ctx, - float width, float height, boolean invert); +void +cso_set_viewport_dims(struct cso_context *ctx, + float width, float height, boolean invert); -void cso_set_sample_mask(struct cso_context *cso, unsigned stencil_mask); +void +cso_set_sample_mask(struct cso_context *cso, unsigned stencil_mask); -void cso_set_min_samples(struct cso_context *cso, unsigned min_samples); +void +cso_set_min_samples(struct cso_context *cso, unsigned min_samples); -void cso_set_stencil_ref(struct cso_context *cso, - const struct pipe_stencil_ref sr); +void +cso_set_stencil_ref(struct cso_context *cso, + const struct pipe_stencil_ref sr); -void cso_set_render_condition(struct cso_context *cso, - struct pipe_query *query, - boolean condition, - enum pipe_render_cond_flag mode); +void +cso_set_render_condition(struct cso_context *cso, + struct pipe_query *query, + boolean condition, + enum pipe_render_cond_flag mode); /* gap */ #define CSO_BIT_BLEND 0x2 @@ -175,11 +186,18 @@ void cso_set_render_condition(struct cso_context *cso, #define CSO_BIT_COMPUTE_SHADER (1<<0) #define CSO_BIT_COMPUTE_SAMPLERS (1<<1) -void cso_save_state(struct cso_context *cso, unsigned state_mask); -void cso_restore_state(struct cso_context *cso, unsigned unbind); +void +cso_save_state(struct cso_context *cso, unsigned state_mask); + +void +cso_restore_state(struct cso_context *cso, unsigned unbind); + +void +cso_save_compute_state(struct cso_context *cso, unsigned state_mask); + +void +cso_restore_compute_state(struct cso_context *cso); -void cso_save_compute_state(struct cso_context *cso, unsigned state_mask); -void cso_restore_compute_state(struct cso_context *cso); /* Optimized version. */ void @@ -191,8 +209,6 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, bool uses_user_vertex_buffers, const struct pipe_vertex_buffer *vbuffers); -/* drawing */ - void cso_draw_vbo(struct cso_context *cso, const struct pipe_draw_info *info,