Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_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_inlines.h"36#include "util/u_draw.h"37#include "util/u_prim.h"3839#include "sp_context.h"40#include "sp_query.h"41#include "sp_state.h"42#include "sp_texture.h"43#include "sp_screen.h"4445#include "draw/draw_context.h"4647/**48* This function handles drawing indexed and non-indexed prims,49* instanced and non-instanced drawing, with or without min/max element50* indexes.51* All the other drawing functions are expressed in terms of this52* function.53*54* For non-indexed prims, indexBuffer should be NULL.55* For non-instanced drawing, instanceCount should be 1.56* When the min/max element indexes aren't known, minIndex should be 057* and maxIndex should be ~0.58*/59void60softpipe_draw_vbo(struct pipe_context *pipe,61const struct pipe_draw_info *info,62unsigned drawid_offset,63const struct pipe_draw_indirect_info *indirect,64const struct pipe_draw_start_count_bias *draws,65unsigned num_draws)66{67if (num_draws > 1) {68util_draw_multi(pipe, info, drawid_offset, indirect, draws, num_draws);69return;70}7172if (!indirect && (!draws[0].count || !info->instance_count))73return;7475struct softpipe_context *sp = softpipe_context(pipe);76struct draw_context *draw = sp->draw;77const void *mapped_indices = NULL;78unsigned i;7980if (!softpipe_check_render_cond(sp))81return;8283if (indirect && indirect->buffer) {84util_draw_indirect(pipe, info, indirect);85return;86}8788sp->reduced_api_prim = u_reduced_prim(info->mode);8990if (sp->dirty) {91softpipe_update_derived(sp, sp->reduced_api_prim);92}9394/* Map vertex buffers */95for (i = 0; i < sp->num_vertex_buffers; i++) {96const void *buf = sp->vertex_buffer[i].is_user_buffer ?97sp->vertex_buffer[i].buffer.user : NULL;98size_t size = ~0;99if (!buf) {100if (!sp->vertex_buffer[i].buffer.resource) {101continue;102}103buf = softpipe_resource_data(sp->vertex_buffer[i].buffer.resource);104size = sp->vertex_buffer[i].buffer.resource->width0;105}106draw_set_mapped_vertex_buffer(draw, i, buf, size);107}108109/* Map index buffer, if present */110if (info->index_size) {111unsigned available_space = ~0;112mapped_indices = info->has_user_indices ? info->index.user : NULL;113if (!mapped_indices) {114mapped_indices = softpipe_resource_data(info->index.resource);115available_space = info->index.resource->width0;116}117118draw_set_indexes(draw,119(ubyte *) mapped_indices,120info->index_size, available_space);121}122123if (softpipe_screen(sp->pipe.screen)->use_llvm) {124softpipe_prepare_vertex_sampling(sp,125sp->num_sampler_views[PIPE_SHADER_VERTEX],126sp->sampler_views[PIPE_SHADER_VERTEX]);127softpipe_prepare_geometry_sampling(sp,128sp->num_sampler_views[PIPE_SHADER_GEOMETRY],129sp->sampler_views[PIPE_SHADER_GEOMETRY]);130}131132if (sp->gs && !sp->gs->shader.tokens) {133/* we have an empty geometry shader with stream output, so134attach the stream output info to the current vertex shader */135if (sp->vs) {136draw_vs_attach_so(sp->vs->draw_data, &sp->gs->shader.stream_output);137}138}139draw_collect_pipeline_statistics(draw,140sp->active_statistics_queries > 0);141142/* draw! */143draw_vbo(draw, info, drawid_offset, indirect, draws, num_draws);144145/* unmap vertex/index buffers - will cause draw module to flush */146for (i = 0; i < sp->num_vertex_buffers; i++) {147draw_set_mapped_vertex_buffer(draw, i, NULL, 0);148}149if (mapped_indices) {150draw_set_indexes(draw, NULL, 0, 0);151}152153if (softpipe_screen(sp->pipe.screen)->use_llvm) {154softpipe_cleanup_vertex_sampling(sp);155softpipe_cleanup_geometry_sampling(sp);156}157158/*159* TODO: Flush only when a user vertex/index buffer is present160* (or even better, modify draw module to do this161* internally when this condition is seen?)162*/163draw_flush(draw);164165/* Note: leave drawing surfaces mapped */166sp->dirty_render_cache = TRUE;167}168169170