Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_helpers.h
4561 views
/**************************************************************************1*2* Copyright 2012 Marek Olšák <[email protected]>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 THE AUTHORS AND/OR THEIR 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#ifndef U_HELPERS_H28#define U_HELPERS_H2930#include "pipe/p_state.h"31#include "c11/threads.h"32#include "compiler/shader_enums.h"33#include <stdio.h>3435#ifdef __cplusplus36extern "C" {37#endif3839void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst,40uint32_t *enabled_buffers,41const struct pipe_vertex_buffer *src,42unsigned start_slot, unsigned count,43unsigned unbind_num_trailing_slots,44bool take_ownership);4546void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,47unsigned *dst_count,48const struct pipe_vertex_buffer *src,49unsigned start_slot, unsigned count,50unsigned unbind_num_trailing_slots,51bool take_ownership);5253void util_set_shader_buffers_mask(struct pipe_shader_buffer *dst,54uint32_t *enabled_buffers,55const struct pipe_shader_buffer *src,56unsigned start_slot, unsigned count);5758bool util_upload_index_buffer(struct pipe_context *pipe,59const struct pipe_draw_info *info,60const struct pipe_draw_start_count_bias *draw,61struct pipe_resource **out_buffer,62unsigned *out_offset, unsigned alignment);6364/* Helper function to determine if the varying should contain the point65* coordinates, given the sprite_coord_enable mask. Requires66* PIPE_CAP_TGSI_TEXCOORD to be enabled.67*/68static inline bool69util_varying_is_point_coord(gl_varying_slot slot, uint32_t sprite_coord_enable)70{71if (slot == VARYING_SLOT_PNTC)72return true;7374if (slot >= VARYING_SLOT_TEX0 && slot <= VARYING_SLOT_TEX7 &&75(sprite_coord_enable & (1 << (slot - VARYING_SLOT_TEX0)))) {76return true;77}7879return false;80}8182struct pipe_query *83util_begin_pipestat_query(struct pipe_context *ctx);8485void86util_end_pipestat_query(struct pipe_context *ctx, struct pipe_query *q,87FILE *f);8889struct pipe_query *90util_begin_time_query(struct pipe_context *ctx);91void92util_end_time_query(struct pipe_context *ctx, struct pipe_query *q, FILE *f,93const char *name);9495void96util_wait_for_idle(struct pipe_context *ctx);9798/* A utility for throttling execution based on memory usage. */99struct util_throttle {100struct {101struct pipe_fence_handle *fence;102uint64_t mem_usage;103} ring[10];104105unsigned flush_index;106unsigned wait_index;107uint64_t max_mem_usage;108};109110void util_throttle_init(struct util_throttle *t, uint64_t max_mem_usage);111void util_throttle_deinit(struct pipe_screen *screen, struct util_throttle *t);112void util_throttle_memory_usage(struct pipe_context *pipe,113struct util_throttle *t, uint64_t memory_size);114115bool116util_lower_clearsize_to_dword(const void *clearValue, int *clearValueSize, uint32_t *clamped);117118#ifdef __cplusplus119}120#endif121122#endif123124125