Path: blob/21.2-virgl/src/gallium/targets/graw-null/graw_util.c
4565 views
1#include "pipe/p_compiler.h"2#include "pipe/p_context.h"3#include "pipe/p_shader_tokens.h"4#include "pipe/p_state.h"5#include "tgsi/tgsi_text.h"6#include "util/u_debug.h"7#include "util/u_debug_image.h"8#include "util/u_memory.h"9#include "frontend/graw.h"101112/* Helper functions. These are the same for all graw implementations.13*/14PUBLIC void *15graw_parse_geometry_shader(struct pipe_context *pipe,16const char *text)17{18struct tgsi_token tokens[1024];19struct pipe_shader_state state;2021if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens)))22return NULL;2324memset(&state, 0, sizeof state);25state.tokens = tokens;26return pipe->create_gs_state(pipe, &state);27}2829PUBLIC void *30graw_parse_vertex_shader(struct pipe_context *pipe,31const char *text)32{33struct tgsi_token tokens[1024];34struct pipe_shader_state state;3536if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens)))37return NULL;3839memset(&state, 0, sizeof state);40state.tokens = tokens;41return pipe->create_vs_state(pipe, &state);42}4344PUBLIC void *45graw_parse_fragment_shader(struct pipe_context *pipe,46const char *text)47{48struct tgsi_token tokens[1024];49struct pipe_shader_state state;5051if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens)))52return NULL;5354memset(&state, 0, sizeof state);55state.tokens = tokens;56return pipe->create_fs_state(pipe, &state);57}5859static char out_filename[256] = "";6061PUBLIC bool62graw_parse_args(int *argi,63int argc,64char *argv[])65{66if (strcmp(argv[*argi], "-o") == 0) {67if (*argi + 1 >= argc) {68return false;69}7071strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1);72out_filename[sizeof(out_filename) - 1] = '\0';73*argi += 2;74return true;75}7677return false;78}7980PUBLIC bool81graw_save_surface_to_file(struct pipe_context *pipe,82struct pipe_surface *surface,83const char *filename)84{85if (!filename || !*filename) {86filename = out_filename;87if (!filename || !*filename) {88return false;89}90}9192/* XXX: Make that working in release builds.93*/94debug_dump_surface_bmp(pipe, filename, surface);95return true;96}979899