1848b8605Smrg 2848b8605Smrg#include "pipe/p_compiler.h" 3848b8605Smrg#include "pipe/p_context.h" 4848b8605Smrg#include "pipe/p_shader_tokens.h" 5848b8605Smrg#include "pipe/p_state.h" 6848b8605Smrg#include "tgsi/tgsi_text.h" 7848b8605Smrg#include "util/u_debug.h" 8b8e80941Smrg#include "util/u_debug_image.h" 9848b8605Smrg#include "util/u_memory.h" 10848b8605Smrg#include "state_tracker/graw.h" 11848b8605Smrg 12848b8605Smrg 13848b8605Smrg/* Helper functions. These are the same for all graw implementations. 14848b8605Smrg */ 15848b8605SmrgPUBLIC void * 16848b8605Smrggraw_parse_geometry_shader(struct pipe_context *pipe, 17848b8605Smrg const char *text) 18848b8605Smrg{ 19848b8605Smrg struct tgsi_token tokens[1024]; 20848b8605Smrg struct pipe_shader_state state; 21848b8605Smrg 22b8e80941Smrg if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) 23848b8605Smrg return NULL; 24848b8605Smrg 25848b8605Smrg memset(&state, 0, sizeof state); 26848b8605Smrg state.tokens = tokens; 27848b8605Smrg return pipe->create_gs_state(pipe, &state); 28848b8605Smrg} 29848b8605Smrg 30848b8605SmrgPUBLIC void * 31848b8605Smrggraw_parse_vertex_shader(struct pipe_context *pipe, 32848b8605Smrg const char *text) 33848b8605Smrg{ 34848b8605Smrg struct tgsi_token tokens[1024]; 35848b8605Smrg struct pipe_shader_state state; 36848b8605Smrg 37b8e80941Smrg if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) 38848b8605Smrg return NULL; 39848b8605Smrg 40848b8605Smrg memset(&state, 0, sizeof state); 41848b8605Smrg state.tokens = tokens; 42848b8605Smrg return pipe->create_vs_state(pipe, &state); 43848b8605Smrg} 44848b8605Smrg 45848b8605SmrgPUBLIC void * 46848b8605Smrggraw_parse_fragment_shader(struct pipe_context *pipe, 47848b8605Smrg const char *text) 48848b8605Smrg{ 49848b8605Smrg struct tgsi_token tokens[1024]; 50848b8605Smrg struct pipe_shader_state state; 51848b8605Smrg 52b8e80941Smrg if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) 53848b8605Smrg return NULL; 54848b8605Smrg 55848b8605Smrg memset(&state, 0, sizeof state); 56848b8605Smrg state.tokens = tokens; 57848b8605Smrg return pipe->create_fs_state(pipe, &state); 58848b8605Smrg} 59848b8605Smrg 60848b8605Smrgstatic char out_filename[256] = ""; 61848b8605Smrg 62848b8605SmrgPUBLIC boolean 63848b8605Smrggraw_parse_args(int *argi, 64848b8605Smrg int argc, 65848b8605Smrg char *argv[]) 66848b8605Smrg{ 67848b8605Smrg if (strcmp(argv[*argi], "-o") == 0) { 68848b8605Smrg if (*argi + 1 >= argc) { 69848b8605Smrg return FALSE; 70848b8605Smrg } 71848b8605Smrg 72848b8605Smrg strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1); 73848b8605Smrg out_filename[sizeof(out_filename) - 1] = '\0'; 74848b8605Smrg *argi += 2; 75848b8605Smrg return TRUE; 76848b8605Smrg } 77848b8605Smrg 78848b8605Smrg return FALSE; 79848b8605Smrg} 80848b8605Smrg 81848b8605SmrgPUBLIC boolean 82848b8605Smrggraw_save_surface_to_file(struct pipe_context *pipe, 83848b8605Smrg struct pipe_surface *surface, 84848b8605Smrg const char *filename) 85848b8605Smrg{ 86848b8605Smrg if (!filename || !*filename) { 87848b8605Smrg filename = out_filename; 88848b8605Smrg if (!filename || !*filename) { 89848b8605Smrg return FALSE; 90848b8605Smrg } 91848b8605Smrg } 92848b8605Smrg 93848b8605Smrg /* XXX: Make that working in release builds. 94848b8605Smrg */ 95848b8605Smrg debug_dump_surface_bmp(pipe, filename, surface); 96848b8605Smrg return TRUE; 97848b8605Smrg} 98