1 2 #include "pipe/p_compiler.h" 3 #include "pipe/p_context.h" 4 #include "pipe/p_shader_tokens.h" 5 #include "pipe/p_state.h" 6 #include "tgsi/tgsi_text.h" 7 #include "util/u_debug.h" 8 #include "util/u_memory.h" 9 #include "state_tracker/graw.h" 10 11 12 /* Helper functions. These are the same for all graw implementations. 13 */ 14 PUBLIC void * 15 graw_parse_geometry_shader(struct pipe_context *pipe, 16 const char *text) 17 { 18 struct tgsi_token tokens[1024]; 19 struct pipe_shader_state state; 20 21 if (!tgsi_text_translate(text, tokens, Elements(tokens))) 22 return NULL; 23 24 state.tokens = tokens; 25 return pipe->create_gs_state(pipe, &state); 26 } 27 28 PUBLIC void * 29 graw_parse_vertex_shader(struct pipe_context *pipe, 30 const char *text) 31 { 32 struct tgsi_token tokens[1024]; 33 struct pipe_shader_state state; 34 35 if (!tgsi_text_translate(text, tokens, Elements(tokens))) 36 return NULL; 37 38 state.tokens = tokens; 39 return pipe->create_vs_state(pipe, &state); 40 } 41 42 PUBLIC void * 43 graw_parse_fragment_shader(struct pipe_context *pipe, 44 const char *text) 45 { 46 struct tgsi_token tokens[1024]; 47 struct pipe_shader_state state; 48 49 if (!tgsi_text_translate(text, tokens, Elements(tokens))) 50 return NULL; 51 52 state.tokens = tokens; 53 return pipe->create_fs_state(pipe, &state); 54 } 55 56 static char out_filename[256] = ""; 57 58 PUBLIC boolean 59 graw_parse_args(int *argi, 60 int argc, 61 char *argv[]) 62 { 63 if (strcmp(argv[*argi], "-o") == 0) { 64 if (*argi + 1 >= argc) { 65 return FALSE; 66 } 67 68 strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1); 69 out_filename[sizeof(out_filename) - 1] = '\0'; 70 *argi += 2; 71 return TRUE; 72 } 73 74 return FALSE; 75 } 76 77 PUBLIC boolean 78 graw_save_surface_to_file(struct pipe_context *pipe, 79 struct pipe_surface *surface, 80 const char *filename) 81 { 82 if (!filename || !*filename) { 83 filename = out_filename; 84 if (!filename || !*filename) { 85 return FALSE; 86 } 87 } 88 89 /* XXX: Make that working in release builds. 90 */ 91 debug_dump_surface_bmp(pipe, filename, surface); 92 return TRUE; 93 } 94