unsigned input_vertex_stride;
const float (*inputs)[4];
-
+ const float (*pre_clip_pos)[4];
boolean has_so;
-
+ boolean use_pre_clip_pos;
+ int pos_idx;
unsigned emitted_primitives;
unsigned emitted_vertices;
unsigned generated_primitives;
};
-void draw_pt_so_emit_prepare(struct pt_so_emit *emit)
+void draw_pt_so_emit_prepare(struct pt_so_emit *emit, boolean use_pre_clip_pos)
{
struct draw_context *draw = emit->draw;
+ emit->use_pre_clip_pos = use_pre_clip_pos;
emit->has_so = (draw->vs.vertex_shader->state.stream_output.num_outputs > 0);
+ if (use_pre_clip_pos)
+ emit->pos_idx = draw_current_shader_position_output(draw);
/* if we have a state with outputs make sure we have
* buffers to output to */
draw_do_flush( draw, DRAW_FLUSH_BACKEND );
}
-static boolean
-is_component_writable(unsigned mask,
- unsigned compo)
-{
- switch (mask) {
- case TGSI_WRITEMASK_NONE:
- return FALSE;
- case TGSI_WRITEMASK_X:
- return compo == 0;
- case TGSI_WRITEMASK_Y:
- return compo == 1;
- case TGSI_WRITEMASK_XY:
- return compo == 0 || compo == 1;
- case TGSI_WRITEMASK_Z:
- return compo == 2;
- case TGSI_WRITEMASK_XZ:
- return compo == 0 || compo == 2;
- case TGSI_WRITEMASK_YZ:
- return compo == 1 || compo == 2;
- case TGSI_WRITEMASK_XYZ:
- return compo == 0 || compo == 1 || compo == 2;
- case TGSI_WRITEMASK_W:
- return compo == 3;
- case TGSI_WRITEMASK_XW:
- return compo == 0 || compo == 3;
- case TGSI_WRITEMASK_YW:
- return compo == 1 || compo == 3;
- case TGSI_WRITEMASK_XYW:
- return compo == 0 || compo == 1 || compo == 3;
- case TGSI_WRITEMASK_ZW:
- return compo == 2 || compo == 3;
- case TGSI_WRITEMASK_XZW:
- return compo == 0 || compo == 1 || compo == 3;
- case TGSI_WRITEMASK_YZW:
- return compo == 1 || compo == 2 || compo == 4;
- case TGSI_WRITEMASK_XYZW:
- return compo < 4;
- default:
- debug_assert(!"Unknown writemask in stream out");
- return compo < 4;
- }
-}
-
-static INLINE int mask_num_comps(int register_mask)
-{
- int comps = 0;
- switch (register_mask) {
- case TGSI_WRITEMASK_XYZW:
- comps = 4;
- break;
- case TGSI_WRITEMASK_XYZ:
- comps = 3;
- break;
- case TGSI_WRITEMASK_XY:
- comps = 2;
- break;
- case TGSI_WRITEMASK_X:
- comps = 1;
- break;
- default:
- assert(0);
- break;
- }
- return comps;
-}
-
static void so_emit_prim(struct pt_so_emit *so,
unsigned *indices,
unsigned num_vertices)
unsigned input_vertex_stride = so->input_vertex_stride;
struct draw_context *draw = so->draw;
const float (*input_ptr)[4];
+ const float (*pcp_ptr)[4] = NULL;
const struct pipe_stream_output_info *state =
&draw->vs.vertex_shader->state.stream_output;
float *buffer;
int buffer_total_bytes[PIPE_MAX_SO_BUFFERS];
input_ptr = so->inputs;
+ if (so->use_pre_clip_pos)
+ pcp_ptr = so->pre_clip_pos;
++so->generated_primitives;
/* check have we space to emit prim first - if not don't do anything */
for (i = 0; i < num_vertices; ++i) {
for (slot = 0; slot < state->num_outputs; ++slot) {
- unsigned writemask = state->output[slot].register_mask;
+ unsigned num_comps = state->output[slot].num_components;
int ob = state->output[slot].output_buffer;
- if ((buffer_total_bytes[ob] + mask_num_comps(writemask) * sizeof(float)) >
+ if ((buffer_total_bytes[ob] + num_comps * sizeof(float)) >
draw->so.targets[ob]->target.buffer_size) {
return;
}
- buffer_total_bytes[ob] += mask_num_comps(writemask) * sizeof(float);
+ buffer_total_bytes[ob] += num_comps * sizeof(float);
}
}
for (i = 0; i < num_vertices; ++i) {
const float (*input)[4];
+ const float (*pre_clip_pos)[4];
unsigned total_written_compos = 0;
+ int ob;
/*debug_printf("%d) vertex index = %d (prim idx = %d)\n", i, indices[i], prim_idx);*/
input = (const float (*)[4])(
(const char *)input_ptr + (indices[i] * input_vertex_stride));
+ if (pcp_ptr)
+ pre_clip_pos = (const float (*)[4])(
+ (const char *)pcp_ptr + (indices[i] * input_vertex_stride));
+
for (slot = 0; slot < state->num_outputs; ++slot) {
unsigned idx = state->output[slot].register_index;
- unsigned writemask = state->output[slot].register_mask;
- unsigned written_compos = 0;
- unsigned compo;
- int ob = state->output[slot].output_buffer;
+ unsigned start_comp = state->output[slot].start_component;
+ unsigned num_comps = state->output[slot].num_components;
+
+ ob = state->output[slot].output_buffer;
buffer = (float *)((char *)draw->so.targets[ob]->mapping +
draw->so.targets[ob]->target.buffer_offset +
- draw->so.targets[ob]->internal_offset);
- for (compo = 0; compo < 4; ++compo) {
- if (is_component_writable(writemask, compo)) {
- buffer[written_compos++] = input[idx][compo];
- }
- }
- draw->so.targets[ob]->internal_offset += written_compos * sizeof(float);
- total_written_compos += written_compos;
+ draw->so.targets[ob]->internal_offset) + state->output[slot].dst_offset;
+ if (idx == so->pos_idx && pcp_ptr)
+ memcpy(buffer, &pre_clip_pos[start_comp], num_comps * sizeof(float));
+ else
+ memcpy(buffer, &input[idx][start_comp], num_comps * sizeof(float));
+ total_written_compos += num_comps;
}
+ for (ob = 0; ob < draw->so.num_targets; ++ob)
+ draw->so.targets[ob]->internal_offset += state->stride[ob] * sizeof(float);
}
so->emitted_vertices += num_vertices;
++so->emitted_primitives;
{
struct draw_context *draw = emit->draw;
struct vbuf_render *render = draw->render;
- struct pipe_stream_output_info *so;
unsigned start, i;
if (!emit->has_so)
return;
- so = &draw->vs.vertex_shader->state.stream_output;
+ if (!draw->so.num_targets)
+ return;
+
emit->emitted_vertices = 0;
emit->emitted_primitives = 0;
emit->generated_primitives = 0;
emit->input_vertex_stride = input_verts->stride;
+ if (emit->use_pre_clip_pos)
+ emit->pre_clip_pos = (const float (*)[4])input_verts->verts->pre_clip_pos;
+
emit->inputs = (const float (*)[4])input_verts->verts->data;
/* XXX: need to flush to get prim_vbuf.c to release its allocation??*/