1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2012 Marek Olšák <maraeo@gmail.com> 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef U_HELPERS_H 29bf215546Sopenharmony_ci#define U_HELPERS_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "pipe/p_state.h" 32bf215546Sopenharmony_ci#include "c11/threads.h" 33bf215546Sopenharmony_ci#include "compiler/shader_enums.h" 34bf215546Sopenharmony_ci#include <stdio.h> 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#ifdef __cplusplus 37bf215546Sopenharmony_ciextern "C" { 38bf215546Sopenharmony_ci#endif 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_civoid util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, 41bf215546Sopenharmony_ci uint32_t *enabled_buffers, 42bf215546Sopenharmony_ci const struct pipe_vertex_buffer *src, 43bf215546Sopenharmony_ci unsigned start_slot, unsigned count, 44bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 45bf215546Sopenharmony_ci bool take_ownership); 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_civoid util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, 48bf215546Sopenharmony_ci unsigned *dst_count, 49bf215546Sopenharmony_ci const struct pipe_vertex_buffer *src, 50bf215546Sopenharmony_ci unsigned start_slot, unsigned count, 51bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 52bf215546Sopenharmony_ci bool take_ownership); 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_civoid util_set_shader_buffers_mask(struct pipe_shader_buffer *dst, 55bf215546Sopenharmony_ci uint32_t *enabled_buffers, 56bf215546Sopenharmony_ci const struct pipe_shader_buffer *src, 57bf215546Sopenharmony_ci unsigned start_slot, unsigned count); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_cibool util_upload_index_buffer(struct pipe_context *pipe, 60bf215546Sopenharmony_ci const struct pipe_draw_info *info, 61bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw, 62bf215546Sopenharmony_ci struct pipe_resource **out_buffer, 63bf215546Sopenharmony_ci unsigned *out_offset, unsigned alignment); 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_civoid 66bf215546Sopenharmony_ciutil_lower_uint64_vertex_elements(const struct pipe_vertex_element **velems, 67bf215546Sopenharmony_ci unsigned *velem_count, 68bf215546Sopenharmony_ci struct pipe_vertex_element tmp[PIPE_MAX_ATTRIBS]); 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci/* Helper function to determine if the varying should contain the point 71bf215546Sopenharmony_ci * coordinates, given the sprite_coord_enable mask. Requires 72bf215546Sopenharmony_ci * PIPE_CAP_TGSI_TEXCOORD to be enabled. 73bf215546Sopenharmony_ci */ 74bf215546Sopenharmony_cistatic inline bool 75bf215546Sopenharmony_ciutil_varying_is_point_coord(gl_varying_slot slot, uint32_t sprite_coord_enable) 76bf215546Sopenharmony_ci{ 77bf215546Sopenharmony_ci if (slot == VARYING_SLOT_PNTC) 78bf215546Sopenharmony_ci return true; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci if (slot >= VARYING_SLOT_TEX0 && slot <= VARYING_SLOT_TEX7 && 81bf215546Sopenharmony_ci (sprite_coord_enable & (1 << (slot - VARYING_SLOT_TEX0)))) { 82bf215546Sopenharmony_ci return true; 83bf215546Sopenharmony_ci } 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci return false; 86bf215546Sopenharmony_ci} 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_cistruct pipe_query * 89bf215546Sopenharmony_ciutil_begin_pipestat_query(struct pipe_context *ctx); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_civoid 92bf215546Sopenharmony_ciutil_end_pipestat_query(struct pipe_context *ctx, struct pipe_query *q, 93bf215546Sopenharmony_ci FILE *f); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_cistruct pipe_query * 96bf215546Sopenharmony_ciutil_begin_time_query(struct pipe_context *ctx); 97bf215546Sopenharmony_civoid 98bf215546Sopenharmony_ciutil_end_time_query(struct pipe_context *ctx, struct pipe_query *q, FILE *f, 99bf215546Sopenharmony_ci const char *name); 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_civoid 102bf215546Sopenharmony_ciutil_wait_for_idle(struct pipe_context *ctx); 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci/* A utility for throttling execution based on memory usage. */ 105bf215546Sopenharmony_cistruct util_throttle { 106bf215546Sopenharmony_ci struct { 107bf215546Sopenharmony_ci struct pipe_fence_handle *fence; 108bf215546Sopenharmony_ci uint64_t mem_usage; 109bf215546Sopenharmony_ci } ring[10]; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci unsigned flush_index; 112bf215546Sopenharmony_ci unsigned wait_index; 113bf215546Sopenharmony_ci uint64_t max_mem_usage; 114bf215546Sopenharmony_ci}; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_civoid util_throttle_init(struct util_throttle *t, uint64_t max_mem_usage); 117bf215546Sopenharmony_civoid util_throttle_deinit(struct pipe_screen *screen, struct util_throttle *t); 118bf215546Sopenharmony_civoid util_throttle_memory_usage(struct pipe_context *pipe, 119bf215546Sopenharmony_ci struct util_throttle *t, uint64_t memory_size); 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_cibool 122bf215546Sopenharmony_ciutil_lower_clearsize_to_dword(const void *clearValue, int *clearValueSize, uint32_t *clamped); 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_civoid 125bf215546Sopenharmony_ciutil_init_pipe_vertex_state(struct pipe_screen *screen, 126bf215546Sopenharmony_ci struct pipe_vertex_buffer *buffer, 127bf215546Sopenharmony_ci const struct pipe_vertex_element *elements, 128bf215546Sopenharmony_ci unsigned num_elements, 129bf215546Sopenharmony_ci struct pipe_resource *indexbuf, 130bf215546Sopenharmony_ci uint32_t full_velem_mask, 131bf215546Sopenharmony_ci struct pipe_vertex_state *state); 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ciunion pipe_color_union util_clamp_color(enum pipe_format format, 134bf215546Sopenharmony_ci const union pipe_color_union *color); 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci#ifdef __cplusplus 137bf215546Sopenharmony_ci} 138bf215546Sopenharmony_ci#endif 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci#endif 141