static INLINE void check_space( struct vbuf_stage *vbuf, unsigned nr ) { if (vbuf->nr_vertices + nr > vbuf->max_vertices || vbuf->nr_indices + nr > vbuf->max_indices) { vbuf_flush_vertices( vbuf ); vbuf_alloc_vertices( vbuf ); } }
/** * Set the prim type for subsequent vertices. * This may result in a new vertex size. The existing vbuffer (if any) * will be flushed if needed and a new one allocated. */ static void vbuf_start_prim( struct vbuf_stage *vbuf, uint prim ) { struct translate_key hw_key; unsigned dst_offset; unsigned i; vbuf->render->set_primitive(vbuf->render, prim); /* Must do this after set_primitive() above: * * XXX: need some state managment to track when this needs to be * recalculated. The driver should tell us whether there was a * state change. */ vbuf->vinfo = vbuf->render->get_vertex_info(vbuf->render); vbuf->vertex_size = vbuf->vinfo->size * sizeof(float); /* Translate from pipeline vertices to hw vertices. */ dst_offset = 0; for (i = 0; i < vbuf->vinfo->num_attribs; i++) { unsigned emit_sz = 0; unsigned src_buffer = 0; unsigned output_format; unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) ); switch (vbuf->vinfo->attrib[i].emit) { case EMIT_4F: output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; emit_sz = 4 * sizeof(float); break; case EMIT_3F: output_format = PIPE_FORMAT_R32G32B32_FLOAT; emit_sz = 3 * sizeof(float); break; case EMIT_2F: output_format = PIPE_FORMAT_R32G32_FLOAT; emit_sz = 2 * sizeof(float); break; case EMIT_1F: output_format = PIPE_FORMAT_R32_FLOAT; emit_sz = 1 * sizeof(float); break; case EMIT_1F_PSIZE: output_format = PIPE_FORMAT_R32_FLOAT; emit_sz = 1 * sizeof(float); src_buffer = 1; src_offset = 0; break; case EMIT_4UB: output_format = PIPE_FORMAT_B8G8R8A8_UNORM; emit_sz = 4 * sizeof(ubyte); break; default: assert(0); output_format = PIPE_FORMAT_NONE; emit_sz = 0; break; } hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; hw_key.element[i].input_buffer = src_buffer; hw_key.element[i].input_offset = src_offset; hw_key.element[i].output_format = output_format; hw_key.element[i].output_offset = dst_offset; dst_offset += emit_sz; } hw_key.nr_elements = vbuf->vinfo->num_attribs; hw_key.output_stride = vbuf->vinfo->size * 4; /* Don't bother with caching at this stage: */ if (!vbuf->translate || translate_key_compare(&vbuf->translate->key, &hw_key) != 0) { translate_key_sanitize(&hw_key); vbuf->translate = translate_cache_find(vbuf->cache, &hw_key); vbuf->translate->set_buffer(vbuf->translate, 1, &vbuf->point_size, 0); } vbuf->point_size = vbuf->stage.draw->rasterizer->point_size; /* Allocate new buffer? */ assert(vbuf->vertices == NULL); vbuf_alloc_vertices(vbuf); }
/** * Set the prim type for subsequent vertices. * This may result in a new vertex size. The existing vbuffer (if any) * will be flushed if needed and a new one allocated. */ static void vbuf_start_prim( struct vbuf_stage *vbuf, uint prim ) { struct translate_key hw_key; unsigned dst_offset; unsigned i; const struct vertex_info *vinfo; vbuf->render->set_primitive(vbuf->render, prim); /* Must do this after set_primitive() above: * * XXX: need some state managment to track when this needs to be * recalculated. The driver should tell us whether there was a * state change. */ vbuf->vinfo = vbuf->render->get_vertex_info(vbuf->render); vinfo = vbuf->vinfo; vbuf->vertex_size = vinfo->size * sizeof(float); /* Translate from pipeline vertices to hw vertices. */ dst_offset = 0; for (i = 0; i < vinfo->num_attribs; i++) { unsigned emit_sz = 0; unsigned src_buffer = 0; enum pipe_format output_format; unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) ); output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); /* doesn't handle EMIT_OMIT */ assert(emit_sz != 0); if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { src_buffer = 1; src_offset = 0; } else if (vinfo->attrib[i].src_index == DRAW_ATTR_NONEXIST) { /* elements which don't exist will get assigned zeros */ src_buffer = 2; src_offset = 0; } hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; hw_key.element[i].input_buffer = src_buffer; hw_key.element[i].input_offset = src_offset; hw_key.element[i].instance_divisor = 0; hw_key.element[i].output_format = output_format; hw_key.element[i].output_offset = dst_offset; dst_offset += emit_sz; } hw_key.nr_elements = vinfo->num_attribs; hw_key.output_stride = vbuf->vertex_size; /* Don't bother with caching at this stage: */ if (!vbuf->translate || translate_key_compare(&vbuf->translate->key, &hw_key) != 0) { translate_key_sanitize(&hw_key); vbuf->translate = translate_cache_find(vbuf->cache, &hw_key); vbuf->translate->set_buffer(vbuf->translate, 1, &vbuf->point_size, 0, ~0); vbuf->translate->set_buffer(vbuf->translate, 2, &vbuf->zero4[0], 0, ~0); } vbuf->point_size = vbuf->stage.draw->rasterizer->point_size; /* Allocate new buffer? */ assert(vbuf->vertices == NULL); vbuf_alloc_vertices(vbuf); }