summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <maraeo@gmail.com>2010-04-11 08:28:39 +0200
committerMarek Olšák <maraeo@gmail.com>2010-04-11 10:15:50 +0200
commit146879284c6b844f35afe3a3ef3330726afbe8ac (patch)
tree92c54f39089b1dcc54d7b5916778c07e60c08472 /src
parent08afcaa56e187cdd137a5c6581c265c1a0fc8d18 (diff)
r300g: revisit some assertions and fix potential failures
* Turn some assertions to error messages. * At most 16 vertex elements can be set, others are ignored. * Rasterize at most 8 vertex-shader generic outputs, others are ignored. This includes fog and WPOS. * Unknown shader semantic names are ignored.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/r300/r300_emit.c4
-rw-r--r--src/gallium/drivers/r300/r300_fs.c3
-rw-r--r--src/gallium/drivers/r300/r300_render.c12
-rw-r--r--src/gallium/drivers/r300/r300_state.c9
-rw-r--r--src/gallium/drivers/r300/r300_state_derived.c10
-rw-r--r--src/gallium/drivers/r300/r300_vs.c35
6 files changed, 42 insertions, 31 deletions
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 60ec164dde..63cd41a57b 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -1114,10 +1114,6 @@ void r300_emit_dirty_state(struct r300_context* r300)
r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS;
}
- /* XXX
- assert(r300->dirty_state == 0);
- */
-
/* Emit the VBO for SWTCL. */
if (!r300screen->caps.has_tcl) {
r300_emit_vertex_buffer(r300);
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index 0444e58f0d..d9319525d4 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -69,7 +69,8 @@ void r300_shader_read_fs_inputs(struct tgsi_shader_info* info,
break;
default:
- assert(0);
+ fprintf(stderr, "r300: FP: Unknown input semantic: %i\n",
+ info->input_semantic_name[i]);
}
}
}
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 44da7aa377..751a7e6d5b 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -273,7 +273,11 @@ void r500_emit_draw_arrays(struct r300_context *r300,
CS_LOCALS(r300);
if (alt_num_verts) {
- assert(count < (1 << 24));
+ if (count >= (1 << 24)) {
+ fprintf(stderr, "r300: Got a huge number of vertices: %i, "
+ "refusing to render.\n", count);
+ return;
+ }
BEGIN_CS(9);
OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
} else {
@@ -309,7 +313,11 @@ void r500_emit_draw_elements(struct r300_context *r300,
#endif
CS_LOCALS(r300);
- assert(count < (1 << 24));
+ if (count >= (1 << 24)) {
+ fprintf(stderr, "r300: Got a huge number of vertices: %i, "
+ "refusing to render.\n", count);
+ return;
+ }
maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index);
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 95ce1a9600..6e69155068 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1128,10 +1128,9 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
if (buffers[i].buffer) {
if (buffers[i].stride % 4 != 0) {
// XXX Shouldn't we align the buffer?
- fprintf(stderr, "r300_set_vertex_buffers: "
+ fprintf(stderr, "r300: set_vertex_buffers: "
"Unaligned buffer stride %i isn't supported.\n",
buffers[i].stride);
- assert(0);
abort();
}
}
@@ -1193,7 +1192,11 @@ static void r300_vertex_psc(struct r300_vertex_element_state *velems)
enum pipe_format format;
unsigned i;
- assert(velems->count <= 16);
+ if (velems->count > 16) {
+ fprintf(stderr, "r300: More than 16 vertex elements are not supported,"
+ " requested %i, using 16.\n", velems->count);
+ velems->count = 16;
+ }
/* Vertex shaders have no semantics on their inputs,
* so PSC should just route stuff based on the vertex elements,
diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c
index 9496815383..10e854dac9 100644
--- a/src/gallium/drivers/r300/r300_state_derived.c
+++ b/src/gallium/drivers/r300/r300_state_derived.c
@@ -83,8 +83,10 @@ static void r300_draw_emit_all_attribs(struct r300_context* r300)
/* XXX Back-face colors. */
/* Texture coordinates. */
+ /* Only 8 generic vertex attributes can be used. If there are more,
+ * they won't be rasterized. */
gen_count = 0;
- for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
+ for (i = 0; i < ATTR_GENERIC_COUNT && gen_count < 8; i++) {
if (vs_outputs->generic[i] != ATTR_UNUSED) {
r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
vs_outputs->generic[i]);
@@ -93,13 +95,11 @@ static void r300_draw_emit_all_attribs(struct r300_context* r300)
}
/* Fog coordinates. */
- if (vs_outputs->fog != ATTR_UNUSED) {
+ if (gen_count < 8 && vs_outputs->fog != ATTR_UNUSED) {
r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
vs_outputs->fog);
gen_count++;
}
-
- assert(gen_count <= 8);
}
/* Update the PSC tables for SW TCL, using Draw. */
@@ -344,7 +344,7 @@ static void r300_update_rs_block(struct r300_context* r300,
/* Rasterize WPOS. */
/* If the FS doesn't need it, it's not written by the VS. */
- if (fs_inputs->wpos != ATTR_UNUSED) {
+ if (vs_outputs->wpos != ATTR_UNUSED && fs_inputs->wpos != ATTR_UNUSED) {
rX00_rs_tex(&rs, tex_count, tex_count, FALSE);
rX00_rs_tex_write(&rs, tex_count, fp_offset);
diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c
index b9b049afad..d8900f73eb 100644
--- a/src/gallium/drivers/r300/r300_vs.c
+++ b/src/gallium/drivers/r300/r300_vs.c
@@ -80,11 +80,12 @@ static void r300_shader_read_vs_outputs(
case TGSI_SEMANTIC_EDGEFLAG:
assert(index == 0);
- fprintf(stderr, "r300 VP: cannot handle edgeflag output\n");
- assert(0);
+ fprintf(stderr, "r300 VP: cannot handle edgeflag output.\n");
break;
+
default:
- assert(0);
+ fprintf(stderr, "r300 VP: unknown vertex output semantic: %i.\n",
+ info->output_semantic_name[i]);
}
}
@@ -148,34 +149,32 @@ static void r300_init_vs_output_mapping(struct r300_vertex_shader* vs)
/* Texture coordinates. */
gen_count = 0;
- for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
+ for (i = 0; i < ATTR_GENERIC_COUNT && gen_count < 8; i++) {
if (vs_outputs->generic[i] != ATTR_UNUSED) {
vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count);
vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count));
- assert(tabi < 16);
stream_loc[tabi++] = 6 + gen_count;
gen_count++;
}
}
/* Fog coordinates. */
- if (vs_outputs->fog != ATTR_UNUSED) {
+ if (gen_count < 8 && vs_outputs->fog != ATTR_UNUSED) {
vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count);
vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count));
- assert(tabi < 16);
stream_loc[tabi++] = 6 + gen_count;
gen_count++;
}
- assert(gen_count <= 8);
-
/* WPOS. */
- vs->wpos_tex_output = gen_count;
-
- assert(tabi < 16);
- stream_loc[tabi++] = 6 + gen_count;
+ if (gen_count < 8) {
+ vs->wpos_tex_output = gen_count;
+ stream_loc[tabi++] = 6 + gen_count;
+ } else {
+ vs_outputs->wpos = ATTR_UNUSED;
+ }
for (; tabi < 16;) {
stream_loc[tabi++] = -1;
@@ -292,7 +291,9 @@ void r300_translate_vertex_shader(struct r300_context* r300,
compiler.SetHwInputOutput = &set_vertex_inputs_outputs;
/* Insert the WPOS output. */
- rc_copy_output(&compiler.Base, 0, vs->outputs.wpos);
+ if (vs->outputs.wpos != ATTR_UNUSED) {
+ rc_copy_output(&compiler.Base, 0, vs->outputs.wpos);
+ }
/* Invoke the compiler */
r3xx_compile_vertex_program(&compiler);
@@ -313,13 +314,15 @@ boolean r300_vertex_shader_setup_wpos(struct r300_context* r300)
int tex_output = vs->wpos_tex_output;
uint32_t tex_fmt = R300_INPUT_CNTL_TC0 << tex_output;
+ if (vs->outputs.wpos == ATTR_UNUSED) {
+ return FALSE;
+ }
+
if (r300->fs->inputs.wpos != ATTR_UNUSED) {
/* Enable WPOS in VAP. */
if (!(vap_out->vap_vsm_vtx_assm & tex_fmt)) {
vap_out->vap_vsm_vtx_assm |= tex_fmt;
vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * tex_output));
-
- assert(tex_output < 8);
return TRUE;
}
} else {