cso_context.c File Reference

Wrap the cso cache & hash mechanisms in a simplified pipe-driver-specific interface. More...

Include dependency graph for cso_context.c:

Go to the source code of this file.

Data Structures

struct  cso_context

Functions

static void free_framebuffer_state (struct pipe_framebuffer_state *fb)
static boolean delete_blend_state (struct cso_context *ctx, void *state)
static boolean delete_depth_stencil_state (struct cso_context *ctx, void *state)
static boolean delete_sampler_state (struct cso_context *ctx, void *state)
static boolean delete_rasterizer_state (struct cso_context *ctx, void *state)
static boolean delete_fs_state (struct cso_context *ctx, void *state)
static boolean delete_vs_state (struct cso_context *ctx, void *state)
static boolean delete_cso (struct cso_context *ctx, void *state, enum cso_cache_type type)
static void sanitize_hash (struct cso_hash *hash, enum cso_cache_type type, int max_size, void *user_data)
struct cso_contextcso_create_context (struct pipe_context *pipe)
void cso_release_all (struct cso_context *ctx)
 Prior to context destruction, this function unbinds all state objects.
void cso_destroy_context (struct cso_context *ctx)
enum pipe_error cso_set_blend (struct cso_context *ctx, const struct pipe_blend_state *templ)
void cso_save_blend (struct cso_context *ctx)
void cso_restore_blend (struct cso_context *ctx)
enum pipe_error cso_single_sampler (struct cso_context *ctx, unsigned idx, const struct pipe_sampler_state *templ)
void cso_single_sampler_done (struct cso_context *ctx)
enum pipe_error cso_set_samplers (struct cso_context *ctx, unsigned nr, const struct pipe_sampler_state **templates)
void cso_save_samplers (struct cso_context *ctx)
void cso_restore_samplers (struct cso_context *ctx)
enum pipe_error cso_set_sampler_textures (struct cso_context *ctx, uint count, struct pipe_texture **textures)
void cso_save_sampler_textures (struct cso_context *ctx)
void cso_restore_sampler_textures (struct cso_context *ctx)
enum pipe_error cso_set_depth_stencil_alpha (struct cso_context *ctx, const struct pipe_depth_stencil_alpha_state *templ)
void cso_save_depth_stencil_alpha (struct cso_context *ctx)
void 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)
void cso_save_rasterizer (struct cso_context *ctx)
void cso_restore_rasterizer (struct cso_context *ctx)
enum pipe_error cso_set_fragment_shader_handle (struct cso_context *ctx, void *handle)
void cso_delete_fragment_shader (struct cso_context *ctx, void *handle)
void cso_save_fragment_shader (struct cso_context *ctx)
void cso_restore_fragment_shader (struct cso_context *ctx)
enum pipe_error cso_set_vertex_shader_handle (struct cso_context *ctx, void *handle)
void cso_delete_vertex_shader (struct cso_context *ctx, void *handle)
void cso_save_vertex_shader (struct cso_context *ctx)
void cso_restore_vertex_shader (struct cso_context *ctx)
static void copy_framebuffer_state (struct pipe_framebuffer_state *dst, const struct pipe_framebuffer_state *src)
 Copy framebuffer state from src to dst with refcounting of surfaces.
enum pipe_error cso_set_framebuffer (struct cso_context *ctx, const struct pipe_framebuffer_state *fb)
void cso_save_framebuffer (struct cso_context *ctx)
void cso_restore_framebuffer (struct cso_context *ctx)
enum pipe_error cso_set_viewport (struct cso_context *ctx, const struct pipe_viewport_state *vp)
void cso_save_viewport (struct cso_context *ctx)
void cso_restore_viewport (struct cso_context *ctx)
enum pipe_error cso_set_blend_color (struct cso_context *ctx, const struct pipe_blend_color *bc)


Detailed Description

Wrap the cso cache & hash mechanisms in a simplified pipe-driver-specific interface.

Author:
Zack Rusin <zack@tungstengraphics.com>

Keith Whitwell <keith@tungstengraphics.com>

Definition in file cso_context.c.


Function Documentation

static void copy_framebuffer_state ( struct pipe_framebuffer_state dst,
const struct pipe_framebuffer_state src 
) [static]

Copy framebuffer state from src to dst with refcounting of surfaces.

Definition at line 779 of file cso_context.c.

References pipe_framebuffer_state::cbufs, pipe_framebuffer_state::height, pipe_framebuffer_state::num_cbufs, PIPE_MAX_COLOR_BUFS, pipe_surface_reference(), pipe_framebuffer_state::width, and pipe_framebuffer_state::zsbuf.

00781 {
00782    uint i;
00783 
00784    dst->width = src->width;
00785    dst->height = src->height;
00786    dst->num_cbufs = src->num_cbufs;
00787    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
00788       pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]);
00789    }
00790    pipe_surface_reference(&dst->zsbuf, src->zsbuf);
00791 }

struct cso_context* cso_create_context ( struct pipe_context pipe  )  [read]

Definition at line 212 of file cso_context.c.

References cso_context::cache, CALLOC_STRUCT, cso_cache_create(), cso_cache_set_sanitize_callback(), cso_destroy_context(), cso_set_maximum_cache_size(), cso_context::pipe, and sanitize_hash().

00213 {
00214    struct cso_context *ctx = CALLOC_STRUCT(cso_context);
00215    if (ctx == NULL)
00216       goto out;
00217 
00218    ctx->cache = cso_cache_create();
00219    if (ctx->cache == NULL)
00220       goto out;
00221    cso_cache_set_sanitize_callback(ctx->cache,
00222                                    sanitize_hash,
00223                                    ctx);
00224 
00225    ctx->pipe = pipe;
00226 
00227    /* Enable for testing: */
00228    if (0) cso_set_maximum_cache_size( ctx->cache, 4 );
00229 
00230    return ctx;
00231 
00232 out:
00233    cso_destroy_context( ctx );      
00234    return NULL;
00235 }

void cso_delete_fragment_shader ( struct cso_context ctx,
void *  handle 
)

Definition at line 625 of file cso_context.c.

References pipe_context::bind_fs_state, pipe_context::delete_fs_state, cso_context::fragment_shader, and cso_context::pipe.

00626 {
00627    if (handle == ctx->fragment_shader) {
00628       /* unbind before deleting */
00629       ctx->pipe->bind_fs_state(ctx->pipe, NULL);
00630       ctx->fragment_shader = NULL;
00631    }
00632    ctx->pipe->delete_fs_state(ctx->pipe, handle);
00633 }

void cso_delete_vertex_shader ( struct cso_context ctx,
void *  handle 
)

Definition at line 706 of file cso_context.c.

References pipe_context::bind_vs_state, pipe_context::delete_vs_state, cso_context::pipe, and cso_context::vertex_shader.

00707 {
00708    if (handle == ctx->vertex_shader) {
00709       /* unbind before deleting */
00710       ctx->pipe->bind_vs_state(ctx->pipe, NULL);
00711       ctx->vertex_shader = NULL;
00712    }
00713    ctx->pipe->delete_vs_state(ctx->pipe, handle);
00714 }

void cso_destroy_context ( struct cso_context ctx  ) 

Definition at line 269 of file cso_context.c.

References FREE.

00270 {
00271    if (ctx) {
00272       //cso_release_all( ctx );
00273       FREE( ctx );
00274    }
00275 }

void cso_release_all ( struct cso_context ctx  ) 

Prior to context destruction, this function unbinds all state objects.

Definition at line 241 of file cso_context.c.

References pipe_context::bind_blend_state, pipe_context::bind_depth_stencil_alpha_state, pipe_context::bind_fs_state, pipe_context::bind_rasterizer_state, pipe_context::bind_sampler_states, pipe_context::bind_vs_state, cso_context::cache, cso_cache_delete(), cso_context::fb_saved, free_framebuffer_state(), cso_context::pipe, PIPE_MAX_SAMPLERS, pipe_texture_reference(), cso_context::textures, and cso_context::textures_saved.

00242 {
00243    unsigned i;
00244    
00245    if (ctx->pipe) {
00246       ctx->pipe->bind_blend_state( ctx->pipe, NULL );
00247       ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL );
00248       ctx->pipe->bind_sampler_states( ctx->pipe, 0, NULL );
00249       ctx->pipe->bind_depth_stencil_alpha_state( ctx->pipe, NULL );
00250       ctx->pipe->bind_fs_state( ctx->pipe, NULL );
00251       ctx->pipe->bind_vs_state( ctx->pipe, NULL );
00252    }
00253 
00254    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
00255       pipe_texture_reference(&ctx->textures[i], NULL);
00256       pipe_texture_reference(&ctx->textures_saved[i], NULL);
00257    }
00258 
00259    free_framebuffer_state(&ctx->fb);
00260    free_framebuffer_state(&ctx->fb_saved);
00261 
00262    if (ctx->cache) {
00263       cso_cache_delete( ctx->cache );
00264       ctx->cache = NULL;
00265    }
00266 }

void cso_restore_blend ( struct cso_context ctx  ) 

Definition at line 332 of file cso_context.c.

References pipe_context::bind_blend_state, cso_context::blend, cso_context::blend_saved, and cso_context::pipe.

00333 {
00334    if (ctx->blend != ctx->blend_saved) {
00335       ctx->blend = ctx->blend_saved;
00336       ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend_saved);
00337    }
00338    ctx->blend_saved = NULL;
00339 }

void cso_restore_depth_stencil_alpha ( struct cso_context ctx  ) 

Definition at line 548 of file cso_context.c.

References pipe_context::bind_depth_stencil_alpha_state, cso_context::depth_stencil, cso_context::depth_stencil_saved, and cso_context::pipe.

00549 {
00550    if (ctx->depth_stencil != ctx->depth_stencil_saved) {
00551       ctx->depth_stencil = ctx->depth_stencil_saved;
00552       ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->depth_stencil_saved);
00553    }
00554    ctx->depth_stencil_saved = NULL;
00555 }

void cso_restore_fragment_shader ( struct cso_context ctx  ) 

Definition at line 686 of file cso_context.c.

References pipe_context::bind_fs_state, cso_context::fragment_shader, cso_context::fragment_shader_saved, and cso_context::pipe.

00687 {
00688    if (ctx->fragment_shader_saved != ctx->fragment_shader) {
00689       ctx->pipe->bind_fs_state(ctx->pipe, ctx->fragment_shader_saved);
00690       ctx->fragment_shader = ctx->fragment_shader_saved;
00691    }
00692    ctx->fragment_shader_saved = NULL;
00693 }

void cso_restore_framebuffer ( struct cso_context ctx  ) 

Definition at line 821 of file cso_context.c.

References copy_framebuffer_state(), cso_context::fb_saved, free_framebuffer_state(), cso_context::pipe, and pipe_context::set_framebuffer_state.

00822 {
00823    if (memcmp(&ctx->fb, &ctx->fb_saved, sizeof(ctx->fb))) {
00824       copy_framebuffer_state(&ctx->fb, &ctx->fb_saved);
00825       ctx->pipe->set_framebuffer_state(ctx->pipe, &ctx->fb);
00826       free_framebuffer_state(&ctx->fb_saved);
00827    }
00828 }

void cso_restore_rasterizer ( struct cso_context ctx  ) 

Definition at line 604 of file cso_context.c.

References pipe_context::bind_rasterizer_state, cso_context::pipe, cso_context::rasterizer, and cso_context::rasterizer_saved.

00605 {
00606    if (ctx->rasterizer != ctx->rasterizer_saved) {
00607       ctx->rasterizer = ctx->rasterizer_saved;
00608       ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rasterizer_saved);
00609    }
00610    ctx->rasterizer_saved = NULL;
00611 }

void cso_restore_sampler_textures ( struct cso_context ctx  ) 

Definition at line 481 of file cso_context.c.

References cso_context::nr_textures, cso_context::nr_textures_saved, cso_context::pipe, PIPE_MAX_SAMPLERS, pipe_texture_reference(), pipe_context::set_sampler_textures, cso_context::textures, and cso_context::textures_saved.

00482 {
00483    uint i;
00484 
00485    ctx->nr_textures = ctx->nr_textures_saved;
00486 
00487    for (i = 0; i < ctx->nr_textures; i++) {
00488       pipe_texture_reference(&ctx->textures[i], NULL);
00489       ctx->textures[i] = ctx->textures_saved[i];
00490       ctx->textures_saved[i] = NULL;
00491    }
00492    for ( ; i < PIPE_MAX_SAMPLERS; i++)
00493       pipe_texture_reference(&ctx->textures[i], NULL);
00494 
00495    ctx->pipe->set_sampler_textures(ctx->pipe, ctx->nr_textures, ctx->textures);
00496 
00497    ctx->nr_textures_saved = 0;
00498 }

void cso_restore_samplers ( struct cso_context ctx  ) 

Definition at line 444 of file cso_context.c.

References cso_single_sampler_done(), cso_context::nr_samplers, cso_context::nr_samplers_saved, cso_context::samplers, and cso_context::samplers_saved.

00445 {
00446    ctx->nr_samplers = ctx->nr_samplers_saved;
00447    memcpy(ctx->samplers, ctx->samplers_saved, sizeof(ctx->samplers));
00448    cso_single_sampler_done( ctx );
00449 }

void cso_restore_vertex_shader ( struct cso_context ctx  ) 

Definition at line 765 of file cso_context.c.

References pipe_context::bind_vs_state, cso_context::pipe, cso_context::vertex_shader, and cso_context::vertex_shader_saved.

00766 {
00767    if (ctx->vertex_shader_saved != ctx->vertex_shader) {
00768       ctx->pipe->bind_vs_state(ctx->pipe, ctx->vertex_shader_saved);
00769       ctx->vertex_shader = ctx->vertex_shader_saved;
00770    }
00771    ctx->vertex_shader_saved = NULL;
00772 }

void cso_restore_viewport ( struct cso_context ctx  ) 

Definition at line 847 of file cso_context.c.

References cso_context::pipe, pipe_context::set_viewport_state, and cso_context::vp_saved.

00848 {
00849    if (memcmp(&ctx->vp, &ctx->vp_saved, sizeof(ctx->vp))) {
00850       ctx->vp = ctx->vp_saved;
00851       ctx->pipe->set_viewport_state(ctx->pipe, &ctx->vp);
00852    }
00853 }

void cso_save_blend ( struct cso_context ctx  ) 

Definition at line 326 of file cso_context.c.

References assert, cso_context::blend, and cso_context::blend_saved.

00327 {
00328    assert(!ctx->blend_saved);
00329    ctx->blend_saved = ctx->blend;
00330 }

void cso_save_depth_stencil_alpha ( struct cso_context ctx  ) 

Definition at line 542 of file cso_context.c.

References assert, cso_context::depth_stencil, and cso_context::depth_stencil_saved.

00543 {
00544    assert(!ctx->depth_stencil_saved);
00545    ctx->depth_stencil_saved = ctx->depth_stencil;
00546 }

void cso_save_fragment_shader ( struct cso_context ctx  ) 

Definition at line 680 of file cso_context.c.

References assert, cso_context::fragment_shader, and cso_context::fragment_shader_saved.

00681 {
00682    assert(!ctx->fragment_shader_saved);
00683    ctx->fragment_shader_saved = ctx->fragment_shader;
00684 }

void cso_save_framebuffer ( struct cso_context ctx  ) 

Definition at line 816 of file cso_context.c.

References copy_framebuffer_state(), and cso_context::fb_saved.

00817 {
00818    copy_framebuffer_state(&ctx->fb_saved, &ctx->fb);
00819 }

void cso_save_rasterizer ( struct cso_context ctx  ) 

Definition at line 598 of file cso_context.c.

References assert, cso_context::rasterizer, and cso_context::rasterizer_saved.

00599 {
00600    assert(!ctx->rasterizer_saved);
00601    ctx->rasterizer_saved = ctx->rasterizer;
00602 }

void cso_save_sampler_textures ( struct cso_context ctx  ) 

Definition at line 470 of file cso_context.c.

References assert, cso_context::nr_textures, cso_context::nr_textures_saved, pipe_texture_reference(), cso_context::textures, and cso_context::textures_saved.

00471 {
00472    uint i;
00473 
00474    ctx->nr_textures_saved = ctx->nr_textures;
00475    for (i = 0; i < ctx->nr_textures; i++) {
00476       assert(!ctx->textures_saved[i]);
00477       pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]);
00478    }
00479 }

void cso_save_samplers ( struct cso_context ctx  ) 

Definition at line 438 of file cso_context.c.

References cso_context::nr_samplers, cso_context::nr_samplers_saved, cso_context::samplers, and cso_context::samplers_saved.

00439 {
00440    ctx->nr_samplers_saved = ctx->nr_samplers;
00441    memcpy(ctx->samplers_saved, ctx->samplers, sizeof(ctx->samplers));
00442 }

void cso_save_vertex_shader ( struct cso_context ctx  ) 

Definition at line 759 of file cso_context.c.

References assert, cso_context::vertex_shader, and cso_context::vertex_shader_saved.

00760 {
00761    assert(!ctx->vertex_shader_saved);
00762    ctx->vertex_shader_saved = ctx->vertex_shader;
00763 }

void cso_save_viewport ( struct cso_context ctx  ) 

Definition at line 841 of file cso_context.c.

References cso_context::vp_saved.

00842 {
00843    ctx->vp_saved = ctx->vp;
00844 }

enum pipe_error cso_set_blend ( struct cso_context ctx,
const struct pipe_blend_state templ 
)

Definition at line 288 of file cso_context.c.

References pipe_context::bind_blend_state, cso_context::blend, cso_context::cache, cso_blend::context, pipe_context::create_blend_state, CSO_BLEND, cso_construct_key(), cso_find_state_template(), cso_hash_iter_data(), cso_hash_iter_is_null(), cso_insert_state(), cso_blend::data, pipe_context::delete_blend_state, cso_blend::delete_state, FREE, hash_key(), MALLOC, cso_context::pipe, PIPE_ERROR_OUT_OF_MEMORY, PIPE_OK, and cso_blend::state.

00290 {
00291    unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_blend_state));
00292    struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
00293                                                        hash_key, CSO_BLEND,
00294                                                        (void*)templ);
00295    void *handle;
00296 
00297    if (cso_hash_iter_is_null(iter)) {
00298       struct cso_blend *cso = MALLOC(sizeof(struct cso_blend));
00299       if (!cso)
00300          return PIPE_ERROR_OUT_OF_MEMORY;
00301 
00302       memcpy(&cso->state, templ, sizeof(*templ));
00303       cso->data = ctx->pipe->create_blend_state(ctx->pipe, &cso->state);
00304       cso->delete_state = (cso_state_callback)ctx->pipe->delete_blend_state;
00305       cso->context = ctx->pipe;
00306 
00307       iter = cso_insert_state(ctx->cache, hash_key, CSO_BLEND, cso);
00308       if (cso_hash_iter_is_null(iter)) {
00309          FREE(cso);
00310          return PIPE_ERROR_OUT_OF_MEMORY;
00311       }
00312 
00313       handle = cso->data;
00314    }
00315    else {
00316       handle = ((struct cso_blend *)cso_hash_iter_data(iter))->data;
00317    }
00318 
00319    if (ctx->blend != handle) {
00320       ctx->blend = handle;
00321       ctx->pipe->bind_blend_state(ctx->pipe, handle);
00322    }
00323    return PIPE_OK;
00324 }

enum pipe_error cso_set_blend_color ( struct cso_context ctx,
const struct pipe_blend_color bc 
)

Definition at line 858 of file cso_context.c.

References cso_context::blend_color, cso_context::pipe, PIPE_OK, and pipe_context::set_blend_color.

00860 {
00861    if (memcmp(&ctx->blend_color, bc, sizeof(ctx->blend_color))) {
00862       ctx->blend_color = *bc;
00863       ctx->pipe->set_blend_color(ctx->pipe, bc);
00864    }
00865    return PIPE_OK;
00866 }

enum pipe_error cso_set_depth_stencil_alpha ( struct cso_context ctx,
const struct pipe_depth_stencil_alpha_state templ 
)

Definition at line 502 of file cso_context.c.

References pipe_context::bind_depth_stencil_alpha_state, cso_context::cache, cso_depth_stencil_alpha::context, pipe_context::create_depth_stencil_alpha_state, cso_construct_key(), CSO_DEPTH_STENCIL_ALPHA, cso_find_state_template(), cso_hash_iter_data(), cso_hash_iter_is_null(), cso_insert_state(), cso_depth_stencil_alpha::data, pipe_context::delete_depth_stencil_alpha_state, cso_depth_stencil_alpha::delete_state, cso_context::depth_stencil, FREE, hash_key(), MALLOC, cso_context::pipe, PIPE_ERROR_OUT_OF_MEMORY, PIPE_OK, and cso_depth_stencil_alpha::state.

00504 {
00505    unsigned hash_key = cso_construct_key((void*)templ,
00506                                          sizeof(struct pipe_depth_stencil_alpha_state));
00507    struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
00508                                                        hash_key, 
00509                                                        CSO_DEPTH_STENCIL_ALPHA,
00510                                                        (void*)templ);
00511    void *handle;
00512 
00513    if (cso_hash_iter_is_null(iter)) {
00514       struct cso_depth_stencil_alpha *cso = MALLOC(sizeof(struct cso_depth_stencil_alpha));
00515       if (!cso)
00516          return PIPE_ERROR_OUT_OF_MEMORY;
00517 
00518       memcpy(&cso->state, templ, sizeof(*templ));
00519       cso->data = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &cso->state);
00520       cso->delete_state = (cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state;
00521       cso->context = ctx->pipe;
00522 
00523       iter = cso_insert_state(ctx->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso);
00524       if (cso_hash_iter_is_null(iter)) {
00525          FREE(cso);
00526          return PIPE_ERROR_OUT_OF_MEMORY;
00527       }
00528 
00529       handle = cso->data;
00530    }
00531    else {
00532       handle = ((struct cso_depth_stencil_alpha *)cso_hash_iter_data(iter))->data;
00533    }
00534 
00535    if (ctx->depth_stencil != handle) {
00536       ctx->depth_stencil = handle;
00537       ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, handle);
00538    }
00539    return PIPE_OK;
00540 }

enum pipe_error cso_set_fragment_shader_handle ( struct cso_context ctx,
void *  handle 
)

Definition at line 615 of file cso_context.c.

References pipe_context::bind_fs_state, cso_context::fragment_shader, cso_context::pipe, and PIPE_OK.

00617 {
00618    if (ctx->fragment_shader != handle) {
00619       ctx->fragment_shader = handle;
00620       ctx->pipe->bind_fs_state(ctx->pipe, handle);
00621    }
00622    return PIPE_OK;
00623 }

enum pipe_error cso_set_framebuffer ( struct cso_context ctx,
const struct pipe_framebuffer_state fb 
)

Definition at line 806 of file cso_context.c.

References copy_framebuffer_state(), cso_context::pipe, PIPE_OK, and pipe_context::set_framebuffer_state.

00808 {
00809    if (memcmp(&ctx->fb, fb, sizeof(*fb)) != 0) {
00810       copy_framebuffer_state(&ctx->fb, fb);
00811       ctx->pipe->set_framebuffer_state(ctx->pipe, fb);
00812    }
00813    return PIPE_OK;
00814 }

enum pipe_error cso_set_rasterizer ( struct cso_context ctx,
const struct pipe_rasterizer_state templ 
)

Definition at line 559 of file cso_context.c.

References pipe_context::bind_rasterizer_state, cso_context::cache, cso_rasterizer::context, pipe_context::create_rasterizer_state, cso_construct_key(), cso_find_state_template(), cso_hash_iter_data(), cso_hash_iter_is_null(), cso_insert_state(), CSO_RASTERIZER, cso_rasterizer::data, pipe_context::delete_rasterizer_state, cso_rasterizer::delete_state, FREE, hash_key(), MALLOC, cso_context::pipe, PIPE_ERROR_OUT_OF_MEMORY, PIPE_OK, cso_context::rasterizer, and cso_rasterizer::state.

00561 {
00562    unsigned hash_key = cso_construct_key((void*)templ,
00563                                          sizeof(struct pipe_rasterizer_state));
00564    struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
00565                                                        hash_key, CSO_RASTERIZER,
00566                                                        (void*)templ);
00567    void *handle = NULL;
00568 
00569    if (cso_hash_iter_is_null(iter)) {
00570       struct cso_rasterizer *cso = MALLOC(sizeof(struct cso_rasterizer));
00571       if (!cso)
00572          return PIPE_ERROR_OUT_OF_MEMORY;
00573 
00574       memcpy(&cso->state, templ, sizeof(*templ));
00575       cso->data = ctx->pipe->create_rasterizer_state(ctx->pipe, &cso->state);
00576       cso->delete_state = (cso_state_callback)ctx->pipe->delete_rasterizer_state;
00577       cso->context = ctx->pipe;
00578 
00579       iter = cso_insert_state(ctx->cache, hash_key, CSO_RASTERIZER, cso);
00580       if (cso_hash_iter_is_null(iter)) {
00581          FREE(cso);
00582          return PIPE_ERROR_OUT_OF_MEMORY;
00583       }
00584 
00585       handle = cso->data;
00586    }
00587    else {
00588       handle = ((struct cso_rasterizer *)cso_hash_iter_data(iter))->data;
00589    }
00590 
00591    if (ctx->rasterizer != handle) {
00592       ctx->rasterizer = handle;
00593       ctx->pipe->bind_rasterizer_state(ctx->pipe, handle);
00594    }
00595    return PIPE_OK;
00596 }

enum pipe_error cso_set_sampler_textures ( struct cso_context ctx,
uint  count,
struct pipe_texture **  textures 
)

Definition at line 452 of file cso_context.c.

References cso_context::nr_textures, cso_context::pipe, PIPE_MAX_SAMPLERS, PIPE_OK, pipe_texture_reference(), pipe_context::set_sampler_textures, and cso_context::textures.

00455 {
00456    uint i;
00457 
00458    ctx->nr_textures = count;
00459 
00460    for (i = 0; i < count; i++)
00461       pipe_texture_reference(&ctx->textures[i], textures[i]);
00462    for ( ; i < PIPE_MAX_SAMPLERS; i++)
00463       pipe_texture_reference(&ctx->textures[i], NULL);
00464 
00465    ctx->pipe->set_sampler_textures(ctx->pipe, count, textures);
00466 
00467    return PIPE_OK;
00468 }

enum pipe_error cso_set_samplers ( struct cso_context ctx,
unsigned  nr,
const struct pipe_sampler_state **  templates 
)

Definition at line 411 of file cso_context.c.

References cso_single_sampler(), cso_single_sampler_done(), cso_context::nr_samplers, and PIPE_OK.

00414 {
00415    unsigned i;
00416    enum pipe_error temp, error = PIPE_OK;
00417 
00418    /* TODO: fastpath
00419     */
00420 
00421    for (i = 0; i < nr; i++) {
00422       temp = cso_single_sampler( ctx, i, templates[i] );
00423       if (temp != PIPE_OK)
00424          error = temp;
00425    }
00426 
00427    for ( ; i < ctx->nr_samplers; i++) {
00428       temp = cso_single_sampler( ctx, i, NULL );
00429       if (temp != PIPE_OK)
00430          error = temp;
00431    }
00432 
00433    cso_single_sampler_done( ctx );
00434 
00435    return error;
00436 }

enum pipe_error cso_set_vertex_shader_handle ( struct cso_context ctx,
void *  handle 
)

Definition at line 696 of file cso_context.c.

References pipe_context::bind_vs_state, cso_context::pipe, PIPE_OK, and cso_context::vertex_shader.

00698 {
00699    if (ctx->vertex_shader != handle) {
00700       ctx->vertex_shader = handle;
00701       ctx->pipe->bind_vs_state(ctx->pipe, handle);
00702    }
00703    return PIPE_OK;
00704 }

enum pipe_error cso_set_viewport ( struct cso_context ctx,
const struct pipe_viewport_state vp 
)

Definition at line 831 of file cso_context.c.

References cso_context::pipe, PIPE_OK, and pipe_context::set_viewport_state.

00833 {
00834    if (memcmp(&ctx->vp, vp, sizeof(*vp))) {
00835       ctx->vp = *vp;
00836       ctx->pipe->set_viewport_state(ctx->pipe, vp);
00837    }
00838    return PIPE_OK;
00839 }

enum pipe_error cso_single_sampler ( struct cso_context ctx,
unsigned  idx,
const struct pipe_sampler_state templ 
)

Definition at line 343 of file cso_context.c.

References cso_context::cache, cso_sampler::context, pipe_context::create_sampler_state, cso_construct_key(), cso_find_state_template(), cso_hash_iter_data(), cso_hash_iter_is_null(), cso_insert_state(), CSO_SAMPLER, cso_sampler::data, pipe_context::delete_sampler_state, cso_sampler::delete_state, FREE, hash_key(), MALLOC, cso_context::pipe, PIPE_ERROR_OUT_OF_MEMORY, PIPE_OK, cso_context::samplers, and cso_sampler::state.

00346 {
00347    void *handle = NULL;
00348 
00349    if (templ != NULL) {
00350       unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_sampler_state));
00351       struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
00352                                                           hash_key, CSO_SAMPLER,
00353                                                           (void*)templ);
00354 
00355       if (cso_hash_iter_is_null(iter)) {
00356          struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler));
00357          if (!cso)
00358             return PIPE_ERROR_OUT_OF_MEMORY;
00359 
00360          memcpy(&cso->state, templ, sizeof(*templ));
00361          cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
00362          cso->delete_state = (cso_state_callback)ctx->pipe->delete_sampler_state;
00363          cso->context = ctx->pipe;
00364 
00365          iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso);
00366          if (cso_hash_iter_is_null(iter)) {
00367             FREE(cso);
00368             return PIPE_ERROR_OUT_OF_MEMORY;
00369          }
00370 
00371          handle = cso->data;
00372       }
00373       else {
00374          handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data;
00375       }
00376    }
00377 
00378    ctx->samplers[idx] = handle;
00379    return PIPE_OK;
00380 }

void cso_single_sampler_done ( struct cso_context ctx  ) 

Definition at line 382 of file cso_context.c.

References pipe_context::bind_sampler_states, cso_context::hw, cso_context::nr_samplers, cso_context::pipe, PIPE_MAX_SAMPLERS, and cso_context::samplers.

00383 {
00384    unsigned i;
00385 
00386    /* find highest non-null sampler */
00387    for (i = PIPE_MAX_SAMPLERS; i > 0; i--) {
00388       if (ctx->samplers[i - 1] != NULL)
00389          break;
00390    }
00391 
00392    ctx->nr_samplers = i;
00393 
00394    if (ctx->hw.nr_samplers != ctx->nr_samplers ||
00395        memcmp(ctx->hw.samplers,
00396               ctx->samplers,
00397               ctx->nr_samplers * sizeof(void *)) != 0) 
00398    {
00399       memcpy(ctx->hw.samplers, ctx->samplers, ctx->nr_samplers * sizeof(void *));
00400       ctx->hw.nr_samplers = ctx->nr_samplers;
00401 
00402       ctx->pipe->bind_sampler_states(ctx->pipe, ctx->nr_samplers, ctx->samplers);
00403    }
00404 }

static boolean delete_blend_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 87 of file cso_context.c.

References cso_context::blend, cso_blend::context, cso_blend::data, cso_blend::delete_state, FALSE, FREE, and TRUE.

00088 {
00089    struct cso_blend *cso = (struct cso_blend *)state;
00090 
00091    if (ctx->blend == cso->data)
00092       return FALSE;
00093 
00094    if (cso->delete_state)
00095       cso->delete_state(cso->context, cso->data);
00096    FREE(state);
00097    return TRUE;
00098 }

static boolean delete_cso ( struct cso_context ctx,
void *  state,
enum cso_cache_type  type 
) [static]

Definition at line 158 of file cso_context.c.

References assert, CSO_BLEND, CSO_DEPTH_STENCIL_ALPHA, CSO_FRAGMENT_SHADER, CSO_RASTERIZER, CSO_SAMPLER, CSO_VERTEX_SHADER, delete_blend_state(), delete_depth_stencil_state(), delete_fs_state(), delete_rasterizer_state(), delete_sampler_state(), delete_vs_state(), FALSE, and FREE.

00160 {
00161    switch (type) {
00162    case CSO_BLEND:
00163       return delete_blend_state(ctx, state);
00164       break;
00165    case CSO_SAMPLER:
00166       return delete_sampler_state(ctx, state);
00167       break;
00168    case CSO_DEPTH_STENCIL_ALPHA:
00169       return delete_depth_stencil_state(ctx, state);
00170       break;
00171    case CSO_RASTERIZER:
00172       return delete_rasterizer_state(ctx, state);
00173       break;
00174    case CSO_FRAGMENT_SHADER:
00175       return delete_fs_state(ctx, state);
00176       break;
00177    case CSO_VERTEX_SHADER:
00178       return delete_vs_state(ctx, state);
00179       break;
00180    default:
00181       assert(0);
00182       FREE(state);
00183    }
00184    return FALSE;
00185 }

static boolean delete_depth_stencil_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 100 of file cso_context.c.

References cso_depth_stencil_alpha::context, cso_depth_stencil_alpha::data, cso_depth_stencil_alpha::delete_state, cso_context::depth_stencil, FALSE, FREE, and TRUE.

00101 {
00102    struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state;
00103 
00104    if (ctx->depth_stencil == cso->data)
00105       return FALSE;
00106 
00107    if (cso->delete_state)
00108       cso->delete_state(cso->context, cso->data);
00109    FREE(state);
00110 
00111    return TRUE;
00112 }

static boolean delete_fs_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 135 of file cso_context.c.

References cso_fragment_shader::context, cso_fragment_shader::data, cso_fragment_shader::delete_state, FALSE, cso_context::fragment_shader, FREE, and TRUE.

00136 {
00137    struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state;
00138    if (ctx->fragment_shader == cso->data)
00139       return FALSE;
00140    if (cso->delete_state)
00141       cso->delete_state(cso->context, cso->data);
00142    FREE(state);
00143    return TRUE;
00144 }

static boolean delete_rasterizer_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 123 of file cso_context.c.

References cso_rasterizer::context, cso_rasterizer::data, cso_rasterizer::delete_state, FALSE, FREE, cso_context::rasterizer, and TRUE.

00124 {
00125    struct cso_rasterizer *cso = (struct cso_rasterizer *)state;
00126 
00127    if (ctx->rasterizer == cso->data)
00128       return FALSE;
00129    if (cso->delete_state)
00130       cso->delete_state(cso->context, cso->data);
00131    FREE(state);
00132    return TRUE;
00133 }

static boolean delete_sampler_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 114 of file cso_context.c.

References cso_sampler::context, cso_sampler::data, cso_sampler::delete_state, FREE, and TRUE.

00115 {
00116    struct cso_sampler *cso = (struct cso_sampler *)state;
00117    if (cso->delete_state)
00118       cso->delete_state(cso->context, cso->data);
00119    FREE(state);
00120    return TRUE;
00121 }

static boolean delete_vs_state ( struct cso_context ctx,
void *  state 
) [static]

Definition at line 146 of file cso_context.c.

References cso_vertex_shader::context, cso_vertex_shader::data, cso_vertex_shader::delete_state, FALSE, FREE, TRUE, and cso_context::vertex_shader.

00147 {
00148    struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state;
00149    if (ctx->vertex_shader == cso->data)
00150       return TRUE;
00151    if (cso->delete_state)
00152       cso->delete_state(cso->context, cso->data);
00153    FREE(state);
00154    return FALSE;
00155 }

static void free_framebuffer_state ( struct pipe_framebuffer_state fb  )  [static]

Definition at line 795 of file cso_context.c.

References pipe_framebuffer_state::cbufs, PIPE_MAX_COLOR_BUFS, pipe_surface_reference(), and pipe_framebuffer_state::zsbuf.

00796 {
00797    uint i;
00798 
00799    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
00800       pipe_surface_reference(&fb->cbufs[i], NULL);
00801    }
00802    pipe_surface_reference(&fb->zsbuf, NULL);
00803 }

static void sanitize_hash ( struct cso_hash hash,
enum cso_cache_type  type,
int  max_size,
void *  user_data 
) [static]

Definition at line 187 of file cso_context.c.

References cso_hash_erase(), cso_hash_first_node(), cso_hash_iter_data(), cso_hash_iter_next(), cso_hash_size(), and delete_cso().

00189 {
00190    struct cso_context *ctx = (struct cso_context *)user_data;
00191    /* if we're approach the maximum size, remove fourth of the entries
00192     * otherwise every subsequent call will go through the same */
00193    int hash_size = cso_hash_size(hash);
00194    int max_entries = (max_size > hash_size) ? max_size : hash_size;
00195    int to_remove =  (max_size < max_entries) * max_entries/4;
00196    struct cso_hash_iter iter = cso_hash_first_node(hash);
00197    if (hash_size > max_size)
00198       to_remove += hash_size - max_size;
00199    while (to_remove) {
00200       /*remove elements until we're good */
00201       /*fixme: currently we pick the nodes to remove at random*/
00202       void *cso = cso_hash_iter_data(iter);
00203       if (delete_cso(ctx, cso, type)) {
00204          iter = cso_hash_erase(hash, iter);
00205          --to_remove;
00206       } else
00207          iter = cso_hash_iter_next(iter);
00208    }
00209 }


Generated on Tue Sep 29 06:25:19 2009 for Gallium3D by  doxygen 1.5.4