sp_state_shader.c revision 339e7ec6805e6de8794514c0a935081b5d36d38f
1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include "sp_context.h" 29#include "sp_state.h" 30#include "sp_fs.h" 31 32#include "pipe/p_defines.h" 33#include "pipe/p_util.h" 34#include "pipe/p_inlines.h" 35#include "pipe/p_winsys.h" 36#include "pipe/p_shader_tokens.h" 37#include "draw/draw_context.h" 38#include "tgsi/util/tgsi_dump.h" 39#include "tgsi/util/tgsi_scan.h" 40 41 42void * 43softpipe_create_fs_state(struct pipe_context *pipe, 44 const struct pipe_shader_state *templ) 45{ 46 struct softpipe_context *softpipe = softpipe_context(pipe); 47 struct sp_fragment_shader *state; 48 49 /* debug */ 50 if (softpipe->dump_fs) 51 tgsi_dump(templ->tokens, 0); 52 53 /* codegen */ 54 state = softpipe_create_fs_llvm( softpipe, templ ); 55 if (!state) { 56 state = softpipe_create_fs_sse( softpipe, templ ); 57 if (!state) { 58 state = softpipe_create_fs_exec( softpipe, templ ); 59 } 60 } 61 62 assert(state); 63 64 /* get/save the summary info for this shader */ 65 tgsi_scan_shader(templ->tokens, &state->info); 66 67 return state; 68} 69 70 71void 72softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) 73{ 74 struct softpipe_context *softpipe = softpipe_context(pipe); 75 76 softpipe->fs = (struct sp_fragment_shader *) fs; 77 78 softpipe->dirty |= SP_NEW_FS; 79} 80 81 82void 83softpipe_delete_fs_state(struct pipe_context *pipe, void *fs) 84{ 85 struct sp_fragment_shader *state = fs; 86 87 state->delete( state ); 88} 89 90 91void * 92softpipe_create_vs_state(struct pipe_context *pipe, 93 const struct pipe_shader_state *templ) 94{ 95 struct softpipe_context *softpipe = softpipe_context(pipe); 96 struct sp_vertex_shader *state; 97 98 state = CALLOC_STRUCT(sp_vertex_shader); 99 if (state == NULL ) { 100 return NULL; 101 } 102 103 state->shader = *templ; 104 105 state->draw_data = draw_create_vertex_shader(softpipe->draw, 106 &state->shader); 107 if (state->draw_data == NULL) { 108 FREE( state ); 109 return NULL; 110 } 111 112 return state; 113} 114 115 116void 117softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) 118{ 119 struct softpipe_context *softpipe = softpipe_context(pipe); 120 121 softpipe->vs = (const struct sp_vertex_shader *)vs; 122 123 draw_bind_vertex_shader(softpipe->draw, 124 (softpipe->vs ? softpipe->vs->draw_data : NULL)); 125 126 softpipe->dirty |= SP_NEW_VS; 127} 128 129 130void 131softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) 132{ 133 struct softpipe_context *softpipe = softpipe_context(pipe); 134 135 struct sp_vertex_shader *state = 136 (struct sp_vertex_shader *)vs; 137 138 draw_delete_vertex_shader(softpipe->draw, state->draw_data); 139 FREE( state ); 140} 141 142 143 144void 145softpipe_set_constant_buffer(struct pipe_context *pipe, 146 uint shader, uint index, 147 const struct pipe_constant_buffer *buf) 148{ 149 struct softpipe_context *softpipe = softpipe_context(pipe); 150 struct pipe_winsys *ws = pipe->winsys; 151 152 assert(shader < PIPE_SHADER_TYPES); 153 assert(index == 0); 154 155 /* note: reference counting */ 156 pipe_buffer_reference(ws, 157 &softpipe->constants[shader].buffer, 158 buf->buffer); 159 softpipe->constants[shader].size = buf->size; 160 161 softpipe->dirty |= SP_NEW_CONSTANTS; 162} 163