00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #include "sp_context.h"
00029 #include "sp_state.h"
00030 #include "sp_fs.h"
00031 
00032 #include "pipe/p_defines.h"
00033 #include "util/u_memory.h"
00034 #include "pipe/p_inlines.h"
00035 #include "pipe/p_winsys.h"
00036 #include "pipe/p_shader_tokens.h"
00037 #include "draw/draw_context.h"
00038 #include "tgsi/tgsi_dump.h"
00039 #include "tgsi/tgsi_scan.h"
00040 
00041 
00042 void *
00043 softpipe_create_fs_state(struct pipe_context *pipe,
00044                          const struct pipe_shader_state *templ)
00045 {
00046    struct softpipe_context *softpipe = softpipe_context(pipe);
00047    struct sp_fragment_shader *state;
00048 
00049    
00050    if (softpipe->dump_fs) 
00051       tgsi_dump(templ->tokens, 0);
00052 
00053    
00054    state = softpipe_create_fs_llvm( softpipe, templ );
00055    if (!state) {
00056       state = softpipe_create_fs_sse( softpipe, templ );
00057       if (!state) {
00058          state = softpipe_create_fs_exec( softpipe, templ );
00059       }
00060    }
00061 
00062    assert(state);
00063 
00064    
00065    tgsi_scan_shader(templ->tokens, &state->info);
00066 
00067    return state;
00068 }
00069 
00070 
00071 void
00072 softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
00073 {
00074    struct softpipe_context *softpipe = softpipe_context(pipe);
00075 
00076    softpipe->fs = (struct sp_fragment_shader *) fs;
00077 
00078    softpipe->dirty |= SP_NEW_FS;
00079 }
00080 
00081 
00082 void
00083 softpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
00084 {
00085    struct sp_fragment_shader *state = fs;
00086 
00087    assert(fs != softpipe_context(pipe)->fs);
00088    
00089    state->delete( state );
00090 }
00091 
00092 
00093 void *
00094 softpipe_create_vs_state(struct pipe_context *pipe,
00095                          const struct pipe_shader_state *templ)
00096 {
00097    struct softpipe_context *softpipe = softpipe_context(pipe);
00098    struct sp_vertex_shader *state;
00099 
00100    state = CALLOC_STRUCT(sp_vertex_shader);
00101    if (state == NULL ) {
00102       return NULL;
00103    }
00104 
00105    state->draw_data = draw_create_vertex_shader(softpipe->draw, templ);
00106    if (state->draw_data == NULL) {
00107       FREE( state );
00108       return NULL;
00109    }
00110 
00111    return state;
00112 }
00113 
00114 
00115 void
00116 softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
00117 {
00118    struct softpipe_context *softpipe = softpipe_context(pipe);
00119 
00120    softpipe->vs = (const struct sp_vertex_shader *)vs;
00121 
00122    draw_bind_vertex_shader(softpipe->draw,
00123                            (softpipe->vs ? softpipe->vs->draw_data : NULL));
00124 
00125    softpipe->dirty |= SP_NEW_VS;
00126 }
00127 
00128 
00129 void
00130 softpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
00131 {
00132    struct softpipe_context *softpipe = softpipe_context(pipe);
00133 
00134    struct sp_vertex_shader *state =
00135       (struct sp_vertex_shader *)vs;
00136 
00137    draw_delete_vertex_shader(softpipe->draw, state->draw_data);
00138    FREE( state );
00139 }
00140 
00141 
00142 
00143 void
00144 softpipe_set_constant_buffer(struct pipe_context *pipe,
00145                              uint shader, uint index,
00146                              const struct pipe_constant_buffer *buf)
00147 {
00148    struct softpipe_context *softpipe = softpipe_context(pipe);
00149    struct pipe_winsys *ws = pipe->winsys;
00150 
00151    assert(shader < PIPE_SHADER_TYPES);
00152    assert(index == 0);
00153 
00154    
00155    winsys_buffer_reference(ws,
00156                          &softpipe->constants[shader].buffer,
00157                          buf ? buf->buffer : NULL);
00158    softpipe->constants[shader].size = buf ? buf->size : 0;
00159 
00160    softpipe->dirty |= SP_NEW_CONSTANTS;
00161 }