#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_parse.h"
+#include "tgsi/tgsi_ureg.h"
#include "radeon_compiler.h"
}
}
-void r300_vertex_shader_common_init(struct r300_vertex_shader *vs,
- const struct pipe_shader_state *shader)
+static void r300_dummy_vertex_shader(
+ struct r300_context* r300,
+ struct r300_vertex_shader* shader)
{
- /* Copy state directly into shader. */
- vs->state = *shader;
- vs->state.tokens = tgsi_dup_tokens(shader->tokens);
- tgsi_scan_shader(shader->tokens, &vs->info);
+ struct pipe_shader_state state;
+ struct ureg_program *ureg;
+ struct ureg_dst dst;
+ struct ureg_src imm;
- r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
- r300_init_vs_output_mapping(vs);
+ /* Make a simple vertex shader which outputs (0, 0, 0, 1),
+ * effectively rendering nothing. */
+ ureg = ureg_create(TGSI_PROCESSOR_VERTEX);
+ dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0);
+ imm = ureg_imm4f(ureg, 0, 0, 0, 1);
+
+ ureg_MOV(ureg, dst, imm);
+ ureg_END(ureg);
+
+ state.tokens = ureg_finalize(ureg);
+
+ shader->dummy = TRUE;
+ r300_translate_vertex_shader(r300, shader, state.tokens);
+
+ ureg_destroy(ureg);
}
void r300_translate_vertex_shader(struct r300_context* r300,
- struct r300_vertex_shader* vs)
+ struct r300_vertex_shader* vs,
+ const struct tgsi_token *tokens)
{
struct r300_vertex_program_compiler compiler;
struct tgsi_to_rc ttr;
+ tgsi_scan_shader(tokens, &vs->info);
+ r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
+ r300_init_vs_output_mapping(vs);
+
/* Setup the compiler */
rc_init(&compiler.Base);
if (compiler.Base.Debug) {
debug_printf("r300: Initial vertex program\n");
- tgsi_dump(vs->state.tokens, 0);
+ tgsi_dump(tokens, 0);
}
/* Translate TGSI to our internal representation */
ttr.info = &vs->info;
ttr.use_half_swizzles = FALSE;
- r300_tgsi_to_rc(&ttr, vs->state.tokens);
+ r300_tgsi_to_rc(&ttr, tokens);
compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs+1));
compiler.SetHwInputOutput = &set_vertex_inputs_outputs;
r3xx_compile_vertex_program(&compiler);
if (compiler.Base.Error) {
/* XXX We should fallback using Draw. */
- fprintf(stderr, "r300 VP: Compiler error:\n%s", compiler.Base.ErrorMsg);
- abort();
+ fprintf(stderr, "r300 VP: Compiler error:\n%sUsing a dummy shader"
+ " instead.\n", compiler.Base.ErrorMsg);
+
+ if (vs->dummy) {
+ fprintf(stderr, "r300 VP: Cannot compile the dummy shader! "
+ "Giving up...\n");
+ abort();
+ }
+ r300_dummy_vertex_shader(r300, vs);
}
/* And, finally... */
struct r300_shader_semantics outputs;
struct r300_vap_output_state vap_out;
+ /* Whether the shader was replaced by a dummy one due to a shader
+ * compilation failure. */
+ boolean dummy;
+
/* Stream locations for SWTCL or if TCL is bypassed. */
int stream_loc_notcl[16];
void *draw_vs;
};
-void r300_vertex_shader_common_init(struct r300_vertex_shader *vs,
- const struct pipe_shader_state *shader);
-
void r300_translate_vertex_shader(struct r300_context* r300,
- struct r300_vertex_shader* vs);
+ struct r300_vertex_shader* vs,
+ const struct tgsi_token *tokens);
/* Return TRUE if VAP (hwfmt) needs to be re-emitted. */
boolean r300_vertex_shader_setup_wpos(struct r300_context* r300);