tests: allow passing shader strings directly.

This makes writing tests using text shaders possible
macos/master
Dave Airlie 10 years ago
parent fcaeadc4ad
commit 91ec75a503
  1. 32
      tests/testvirgl_encode.c
  2. 3
      tests/testvirgl_encode.h

@ -178,25 +178,32 @@ int virgl_encode_rasterizer_state(struct virgl_context *ctx,
int virgl_encode_shader_state(struct virgl_context *ctx,
uint32_t handle,
uint32_t type,
const struct pipe_shader_state *shader)
const struct pipe_shader_state *shader,
const char *shad_str)
{
char *str;
uint32_t shader_len, len;
int i;
int ret;
uint32_t tmp;
int num_tokens = tgsi_num_tokens(shader->tokens);
int num_tokens;
int str_total_size = 65536;
str = CALLOC(1, str_total_size);
if (!str)
return -1;
ret = tgsi_dump_str(shader->tokens, TGSI_DUMP_FLOAT_AS_HEX, str, str_total_size);
if (ret == -1) {
fprintf(stderr, "Failed to translate shader in available space\n");
FREE(str);
return -1;
if (!shad_str) {
num_tokens = tgsi_num_tokens(shader->tokens);
str = CALLOC(1, str_total_size);
if (!str)
return -1;
ret = tgsi_dump_str(shader->tokens, TGSI_DUMP_FLOAT_AS_HEX, str, str_total_size);
if (ret == -1) {
fprintf(stderr, "Failed to translate shader in available space\n");
FREE(str);
return -1;
}
} else {
num_tokens = 0;
str = (char *)shad_str;
}
shader_len = strlen(str) + 1;
@ -222,7 +229,8 @@ int virgl_encode_shader_state(struct virgl_context *ctx,
}
virgl_encoder_write_block(ctx->cbuf, (uint8_t *)str, shader_len);
FREE(str);
if (str != shad_str)
FREE(str);
return 0;
}

@ -49,7 +49,8 @@ extern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
extern int virgl_encode_shader_state(struct virgl_context *ctx,
uint32_t handle,
uint32_t type,
const struct pipe_shader_state *shader);
const struct pipe_shader_state *shader,
const char *shad_str);
int virgl_encode_stream_output_info(struct virgl_context *ctx,
uint32_t handle,

Loading…
Cancel
Save