r300->fs = fs;
r300_pick_fragment_shader(r300);
+ if (r300->vs && r300_vertex_shader_setup_wpos(r300)) {
+ r300->dirty_state |= R300_NEW_VERTEX_FORMAT;
+ }
+
r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS;
}
}
r300->vs = vs;
- r300->dirty_state |= R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS;
+ if (r300->fs) {
+ r300_vertex_shader_setup_wpos(r300);
+ }
+
+ r300->dirty_state |=
+ R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS |
+ R300_NEW_VERTEX_FORMAT;
} else {
draw_flush(r300->draw);
draw_bind_vertex_shader(r300->draw,
}
/* Rasterize WPOS. */
- if (vs_outputs->wpos != ATTR_UNUSED) {
- /* Always rasterize if it's written by the VS,
- * otherwise it locks up. */
+ /* If the FS doesn't need it, it's not written by the VS. */
+ if (fs_inputs->wpos != ATTR_UNUSED) {
rX00_rs_tex(rs, tex_count, tex_count, FALSE);
+ rX00_rs_tex_write(rs, tex_count, fp_offset);
- /* Write it to the FS input register if it's used by the FS. */
- if (fs_inputs->wpos != ATTR_UNUSED) {
- rX00_rs_tex_write(rs, tex_count, fp_offset);
- fp_offset++;
- }
+ fp_offset++;
tex_count++;
- } else {
- /* Skip the FS input register, leave it uninitialized. */
- /* If we try to set it to (0,0,0,1), it will lock up. */
- if (fs_inputs->wpos != ATTR_UNUSED) {
- fp_offset++;
- }
}
/* Rasterize at least one color, or bad things happen. */
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "r300_vs.h"
+#include "r300_fs.h"
#include "r300_context.h"
#include "r300_screen.h"
}
}
-static void r300_shader_vap_output_fmt(
- struct r300_shader_semantics* vs_outputs,
- uint* hwfmt)
+static void r300_shader_vap_output_fmt(struct r300_vertex_shader* vs)
{
+ struct r300_shader_semantics* vs_outputs = &vs->outputs;
+ uint32_t* hwfmt = vs->hwfmt;
int i, gen_count;
/* Do the actual vertex_info setup.
gen_count++;
}
- /* WPOS. */
- if (vs_outputs->wpos != ATTR_UNUSED) {
- hwfmt[1] |= (R300_INPUT_CNTL_TC0 << gen_count);
- hwfmt[3] |= (4 << (3 * gen_count));
- gen_count++;
- }
-
/* XXX magic */
assert(gen_count <= 8);
+
+ /* WPOS. */
+ vs->wpos_tex_output = gen_count;
}
/* Sets up stream mapping to equivalent VS outputs if TCL is bypassed
gen_count++;
}
- /* XXX magic */
- assert(gen_count <= 8);
-
for (; tabi < 16;) {
stream_loc[tabi++] = -1;
}
{
struct r300_vertex_program_compiler compiler;
struct tgsi_to_rc ttr;
- boolean use_wpos = TRUE;
/* Initialize. */
r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
r300_tgsi_to_rc(&ttr, vs->state.tokens);
- compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs+use_wpos));
+ compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs+1));
compiler.SetHwInputOutput = &set_vertex_inputs_outputs;
/* Insert the WPOS output. */
- if (use_wpos) {
- r300_insert_wpos(&compiler, &vs->outputs);
- }
+ r300_insert_wpos(&compiler, &vs->outputs);
- r300_shader_vap_output_fmt(&vs->outputs, vs->hwfmt);
+ r300_shader_vap_output_fmt(vs);
r300_stream_locations_notcl(&vs->outputs, vs->stream_loc_notcl);
/* Invoke the compiler */
rc_destroy(&compiler.Base);
vs->translated = TRUE;
}
+
+boolean r300_vertex_shader_setup_wpos(struct r300_context* r300)
+{
+ struct r300_vertex_shader* vs = r300->vs;
+ int tex_output = r300->vs->wpos_tex_output;
+ uint32_t tex_fmt = R300_INPUT_CNTL_TC0 << tex_output;
+ uint32_t* hwfmt = vs->hwfmt;
+
+ if (r300->fs->inputs.wpos != ATTR_UNUSED) {
+ /* Enable WPOS in VAP. */
+ if (!(hwfmt[1] & tex_fmt)) {
+ hwfmt[1] |= tex_fmt;
+ hwfmt[3] |= (4 << (3 * tex_output));
+
+ assert(tex_output < 8);
+ return TRUE;
+ }
+ } else {
+ /* Disable WPOS in VAP. */
+ if (hwfmt[1] & tex_fmt) {
+ hwfmt[1] &= ~tex_fmt;
+ hwfmt[3] &= ~(4 << (3 * tex_output));
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
/* Stream locations for SWTCL or if TCL is bypassed. */
int stream_loc_notcl[16];
+ /* Output stream location for WPOS. */
+ int wpos_tex_output;
+
/* Has this shader been translated yet? */
boolean translated;
void r300_translate_vertex_shader(struct r300_context* r300,
struct r300_vertex_shader* vs);
+/* Return TRUE if VAP (hwfmt) needs to be re-emitted. */
+boolean r300_vertex_shader_setup_wpos(struct r300_context* r300);
+
#endif /* R300_VS_H */