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