#include "etnaviv_context.h"
#include "etnaviv_debug.h"
#include "etnaviv_disasm.h"
+#include "etnaviv_shader.h"
#include "etnaviv_uniforms.h"
#include "etnaviv_util.h"
etna_set_shader_uniforms_dirty_flags(sobj);
}
-struct etna_shader_variant *
-etna_compile_shader(const struct etna_specs *specs,
- const struct tgsi_token *tokens)
+bool
+etna_compile_shader(struct etna_shader_variant *v)
{
/* Create scratch space that may be too large to fit on stack
*/
bool ret;
struct etna_compile *c;
- struct etna_shader_variant *shader;
+
+ if (unlikely(!v))
+ return false;
+
+ const struct etna_specs *specs = v->shader->specs;
struct tgsi_lowering_config lconfig = {
.lower_SCS = specs->has_sin_cos_sqrt,
c = CALLOC_STRUCT(etna_compile);
if (!c)
- return NULL;
+ return false;
- shader = CALLOC_STRUCT(etna_shader_variant);
- if (!shader)
- goto out;
+ const struct tgsi_token *tokens = v->shader->tokens;
c->specs = specs;
c->tokens = tgsi_transform_lowering(&lconfig, tokens, &c->info);
etna_compile_fill_in_labels(c);
ret = etna_compile_check_limits(c);
- if (!ret) {
- FREE(shader);
- shader = NULL;
+ if (!ret)
goto out;
- }
/* fill in output structure */
- shader->processor = c->info.processor;
- shader->code_size = c->inst_ptr * 4;
- shader->code = mem_dup(c->code, c->inst_ptr * 16);
- shader->num_loops = c->num_loops;
- shader->num_temps = c->next_free_native;
- shader->vs_pos_out_reg = -1;
- shader->vs_pointsize_out_reg = -1;
- shader->ps_color_out_reg = -1;
- shader->ps_depth_out_reg = -1;
- copy_uniform_state_to_shader(c, shader);
+ v->processor = c->info.processor;
+ v->code_size = c->inst_ptr * 4;
+ v->code = mem_dup(c->code, c->inst_ptr * 16);
+ v->num_loops = c->num_loops;
+ v->num_temps = c->next_free_native;
+ v->vs_pos_out_reg = -1;
+ v->vs_pointsize_out_reg = -1;
+ v->ps_color_out_reg = -1;
+ v->ps_depth_out_reg = -1;
+ copy_uniform_state_to_shader(c, v);
if (c->info.processor == PIPE_SHADER_VERTEX) {
- fill_in_vs_inputs(shader, c);
- fill_in_vs_outputs(shader, c);
+ fill_in_vs_inputs(v, c);
+ fill_in_vs_outputs(v, c);
} else if (c->info.processor == PIPE_SHADER_FRAGMENT) {
- fill_in_ps_inputs(shader, c);
- fill_in_ps_outputs(shader, c);
+ fill_in_ps_inputs(v, c);
+ fill_in_ps_outputs(v, c);
}
out:
FREE(c->labels);
FREE(c);
- return shader;
+ return ret;
}
extern const char *tgsi_swizzle_names[];
#include "etnaviv_compiler.h"
#include "etnaviv_debug.h"
#include "etnaviv_internal.h"
+#include "etnaviv_shader.h"
+
+#include "util/u_memory.h"
static const struct etna_specs specs_gc2000 = {
.vs_need_z_div = 0,
const char *filename;
struct tgsi_token toks[65536];
struct tgsi_parse_context parse;
- struct etna_shader_variant *shader_obj;
+ struct etna_shader s = {};
void *ptr;
size_t size;
+ struct etna_shader_variant *v = CALLOC_STRUCT(etna_shader_variant);
+ if (!v) {
+ fprintf(stderr, "malloc failed!\n");
+ return 1;
+ }
+
etna_mesa_debug = ETNA_DBG_MSGS;
while (n < argc) {
tgsi_parse_init(&parse, toks);
- shader_obj = etna_compile_shader(&specs_gc2000, toks);
+ s.specs = &specs_gc2000;
+ s.tokens = toks;
+
+ v->shader = &s;
- if (shader_obj == NULL) {
+ if (!etna_compile_shader(v)) {
fprintf(stderr, "compiler failed!\n");
return 1;
}
- etna_dump_shader(shader_obj);
- etna_destroy_shader(shader_obj);
+ etna_dump_shader(v);
+ etna_destroy_shader(v);
}