sp_state_fs.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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    /* debug */
00050    if (softpipe->dump_fs) 
00051       tgsi_dump(templ->tokens, 0);
00052 
00053    /* codegen */
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    /* get/save the summary info for this shader */
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    /* note: reference counting */
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 }

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