Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
4570 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/* Author:28* Brian Paul29* Keith Whitwell30*/313233#include "pipe/p_defines.h"34#include "pipe/p_context.h"35#include "util/u_draw.h"36#include "util/u_prim.h"3738#include "lp_context.h"39#include "lp_state.h"40#include "lp_query.h"4142#include "draw/draw_context.h"43444546/**47* Draw vertex arrays, with optional indexing, optional instancing.48* All the other drawing functions are implemented in terms of this function.49* Basically, map the vertex buffers (and drawing surfaces), then hand off50* the drawing to the 'draw' module.51*/52static void53llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,54unsigned drawid_offset,55const struct pipe_draw_indirect_info *indirect,56const struct pipe_draw_start_count_bias *draws,57unsigned num_draws)58{59if (!indirect && (!draws[0].count || !info->instance_count))60return;6162struct llvmpipe_context *lp = llvmpipe_context(pipe);63struct draw_context *draw = lp->draw;64const void *mapped_indices = NULL;65unsigned i;6667if (!llvmpipe_check_render_cond(lp))68return;6970if (indirect && indirect->buffer) {71util_draw_indirect(pipe, info, indirect);72return;73}7475if (lp->dirty)76llvmpipe_update_derived( lp );7778/*79* Map vertex buffers80*/81for (i = 0; i < lp->num_vertex_buffers; i++) {82const void *buf = lp->vertex_buffer[i].is_user_buffer ?83lp->vertex_buffer[i].buffer.user : NULL;84size_t size = ~0;85if (!buf) {86if (!lp->vertex_buffer[i].buffer.resource) {87continue;88}89buf = llvmpipe_resource_data(lp->vertex_buffer[i].buffer.resource);90size = lp->vertex_buffer[i].buffer.resource->width0;91}92draw_set_mapped_vertex_buffer(draw, i, buf, size);93}9495/* Map index buffer, if present */96if (info->index_size) {97unsigned available_space = ~0;98mapped_indices = info->has_user_indices ? info->index.user : NULL;99if (!mapped_indices) {100mapped_indices = llvmpipe_resource_data(info->index.resource);101available_space = info->index.resource->width0;102}103draw_set_indexes(draw,104(ubyte *) mapped_indices,105info->index_size, available_space);106}107108llvmpipe_prepare_vertex_sampling(lp,109lp->num_sampler_views[PIPE_SHADER_VERTEX],110lp->sampler_views[PIPE_SHADER_VERTEX]);111llvmpipe_prepare_geometry_sampling(lp,112lp->num_sampler_views[PIPE_SHADER_GEOMETRY],113lp->sampler_views[PIPE_SHADER_GEOMETRY]);114llvmpipe_prepare_tess_ctrl_sampling(lp,115lp->num_sampler_views[PIPE_SHADER_TESS_CTRL],116lp->sampler_views[PIPE_SHADER_TESS_CTRL]);117llvmpipe_prepare_tess_eval_sampling(lp,118lp->num_sampler_views[PIPE_SHADER_TESS_EVAL],119lp->sampler_views[PIPE_SHADER_TESS_EVAL]);120121llvmpipe_prepare_vertex_images(lp,122lp->num_images[PIPE_SHADER_VERTEX],123lp->images[PIPE_SHADER_VERTEX]);124llvmpipe_prepare_geometry_images(lp,125lp->num_images[PIPE_SHADER_GEOMETRY],126lp->images[PIPE_SHADER_GEOMETRY]);127llvmpipe_prepare_tess_ctrl_images(lp,128lp->num_images[PIPE_SHADER_TESS_CTRL],129lp->images[PIPE_SHADER_TESS_CTRL]);130llvmpipe_prepare_tess_eval_images(lp,131lp->num_images[PIPE_SHADER_TESS_EVAL],132lp->images[PIPE_SHADER_TESS_EVAL]);133if (lp->gs && lp->gs->no_tokens) {134/* we have an empty geometry shader with stream output, so135attach the stream output info to the current vertex shader */136if (lp->vs) {137draw_vs_attach_so(lp->vs, &lp->gs->stream_output);138}139}140draw_collect_pipeline_statistics(draw,141lp->active_statistics_queries > 0);142143draw_collect_primitives_generated(draw,144lp->active_primgen_queries &&145!lp->queries_disabled);146147/* draw! */148draw_vbo(draw, info, drawid_offset, indirect, draws, num_draws);149150/*151* unmap vertex/index buffers152*/153for (i = 0; i < lp->num_vertex_buffers; i++) {154draw_set_mapped_vertex_buffer(draw, i, NULL, 0);155}156if (mapped_indices) {157draw_set_indexes(draw, NULL, 0, 0);158}159160if (lp->gs && lp->gs->no_tokens) {161/* we have attached stream output to the vs for rendering,162now lets reset it */163if (lp->vs) {164draw_vs_reset_so(lp->vs);165}166}167168llvmpipe_cleanup_stage_sampling(lp, PIPE_SHADER_VERTEX);169llvmpipe_cleanup_stage_sampling(lp, PIPE_SHADER_GEOMETRY);170llvmpipe_cleanup_stage_sampling(lp, PIPE_SHADER_TESS_CTRL);171llvmpipe_cleanup_stage_sampling(lp, PIPE_SHADER_TESS_EVAL);172173llvmpipe_cleanup_stage_images(lp, PIPE_SHADER_VERTEX);174llvmpipe_cleanup_stage_images(lp, PIPE_SHADER_GEOMETRY);175llvmpipe_cleanup_stage_images(lp, PIPE_SHADER_TESS_CTRL);176llvmpipe_cleanup_stage_images(lp, PIPE_SHADER_TESS_EVAL);177178/*179* TODO: Flush only when a user vertex/index buffer is present180* (or even better, modify draw module to do this181* internally when this condition is seen?)182*/183draw_flush(draw);184}185186187void188llvmpipe_init_draw_funcs(struct llvmpipe_context *llvmpipe)189{190llvmpipe->pipe.draw_vbo = llvmpipe_draw_vbo;191}192193194