1af69d88dSmrg/**************************************************************************
2af69d88dSmrg *
3af69d88dSmrg * Copyright 2012 Marek Olšák <maraeo@gmail.com>
4af69d88dSmrg * All Rights Reserved.
5af69d88dSmrg *
6af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
7af69d88dSmrg * copy of this software and associated documentation files (the
8af69d88dSmrg * "Software"), to deal in the Software without restriction, including
9af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish,
10af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to
11af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to
12af69d88dSmrg * the following conditions:
13af69d88dSmrg *
14af69d88dSmrg * The above copyright notice and this permission notice (including the
15af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions
16af69d88dSmrg * of the Software.
17af69d88dSmrg *
18af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR
22af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25af69d88dSmrg *
26af69d88dSmrg **************************************************************************/
27af69d88dSmrg
28af69d88dSmrg#ifndef U_HELPERS_H
29af69d88dSmrg#define U_HELPERS_H
30af69d88dSmrg
3101e04c3fSmrg#include "pipe/p_state.h"
3201e04c3fSmrg#include "c11/threads.h"
337ec681f3Smrg#include "compiler/shader_enums.h"
3401e04c3fSmrg#include <stdio.h>
3501e04c3fSmrg
36af69d88dSmrg#ifdef __cplusplus
37af69d88dSmrgextern "C" {
38af69d88dSmrg#endif
39af69d88dSmrg
40af69d88dSmrgvoid util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst,
41af69d88dSmrg                                  uint32_t *enabled_buffers,
42af69d88dSmrg                                  const struct pipe_vertex_buffer *src,
437ec681f3Smrg                                  unsigned start_slot, unsigned count,
447ec681f3Smrg                                  unsigned unbind_num_trailing_slots,
457ec681f3Smrg                                  bool take_ownership);
46af69d88dSmrg
47af69d88dSmrgvoid util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,
48af69d88dSmrg                                   unsigned *dst_count,
49af69d88dSmrg                                   const struct pipe_vertex_buffer *src,
507ec681f3Smrg                                   unsigned start_slot, unsigned count,
517ec681f3Smrg                                   unsigned unbind_num_trailing_slots,
527ec681f3Smrg                                   bool take_ownership);
537ec681f3Smrg
547ec681f3Smrgvoid util_set_shader_buffers_mask(struct pipe_shader_buffer *dst,
557ec681f3Smrg                                  uint32_t *enabled_buffers,
567ec681f3Smrg                                  const struct pipe_shader_buffer *src,
577ec681f3Smrg                                  unsigned start_slot, unsigned count);
58af69d88dSmrg
5901e04c3fSmrgbool util_upload_index_buffer(struct pipe_context *pipe,
6001e04c3fSmrg                              const struct pipe_draw_info *info,
617ec681f3Smrg                              const struct pipe_draw_start_count_bias *draw,
6201e04c3fSmrg                              struct pipe_resource **out_buffer,
637ec681f3Smrg                              unsigned *out_offset, unsigned alignment);
6401e04c3fSmrg
6501e04c3fSmrgvoid
667ec681f3Smrgutil_lower_uint64_vertex_elements(const struct pipe_vertex_element **velems,
677ec681f3Smrg                                  unsigned *velem_count,
687ec681f3Smrg                                  struct pipe_vertex_element tmp[PIPE_MAX_ATTRIBS]);
697ec681f3Smrg
707ec681f3Smrg/* Helper function to determine if the varying should contain the point
717ec681f3Smrg * coordinates, given the sprite_coord_enable mask.  Requires
727ec681f3Smrg * PIPE_CAP_TGSI_TEXCOORD to be enabled.
737ec681f3Smrg */
747ec681f3Smrgstatic inline bool
757ec681f3Smrgutil_varying_is_point_coord(gl_varying_slot slot, uint32_t sprite_coord_enable)
767ec681f3Smrg{
777ec681f3Smrg   if (slot == VARYING_SLOT_PNTC)
787ec681f3Smrg      return true;
797ec681f3Smrg
807ec681f3Smrg   if (slot >= VARYING_SLOT_TEX0 && slot <= VARYING_SLOT_TEX7 &&
817ec681f3Smrg       (sprite_coord_enable & (1 << (slot - VARYING_SLOT_TEX0)))) {
827ec681f3Smrg      return true;
837ec681f3Smrg   }
847ec681f3Smrg
857ec681f3Smrg   return false;
867ec681f3Smrg}
8701e04c3fSmrg
8801e04c3fSmrgstruct pipe_query *
8901e04c3fSmrgutil_begin_pipestat_query(struct pipe_context *ctx);
9001e04c3fSmrg
9101e04c3fSmrgvoid
9201e04c3fSmrgutil_end_pipestat_query(struct pipe_context *ctx, struct pipe_query *q,
9301e04c3fSmrg                        FILE *f);
9401e04c3fSmrg
957ec681f3Smrgstruct pipe_query *
967ec681f3Smrgutil_begin_time_query(struct pipe_context *ctx);
977ec681f3Smrgvoid
987ec681f3Smrgutil_end_time_query(struct pipe_context *ctx, struct pipe_query *q, FILE *f,
997ec681f3Smrg                    const char *name);
1007ec681f3Smrg
10101e04c3fSmrgvoid
10201e04c3fSmrgutil_wait_for_idle(struct pipe_context *ctx);
10301e04c3fSmrg
10401e04c3fSmrg/* A utility for throttling execution based on memory usage. */
10501e04c3fSmrgstruct util_throttle {
10601e04c3fSmrg   struct {
10701e04c3fSmrg      struct pipe_fence_handle *fence;
10801e04c3fSmrg      uint64_t mem_usage;
10901e04c3fSmrg   } ring[10];
11001e04c3fSmrg
11101e04c3fSmrg   unsigned flush_index;
11201e04c3fSmrg   unsigned wait_index;
11301e04c3fSmrg   uint64_t max_mem_usage;
11401e04c3fSmrg};
11501e04c3fSmrg
11601e04c3fSmrgvoid util_throttle_init(struct util_throttle *t, uint64_t max_mem_usage);
11701e04c3fSmrgvoid util_throttle_deinit(struct pipe_screen *screen, struct util_throttle *t);
11801e04c3fSmrgvoid util_throttle_memory_usage(struct pipe_context *pipe,
11901e04c3fSmrg                                struct util_throttle *t, uint64_t memory_size);
12001e04c3fSmrg
1217ec681f3Smrgbool
1227ec681f3Smrgutil_lower_clearsize_to_dword(const void *clearValue, int *clearValueSize, uint32_t *clamped);
1237ec681f3Smrg
1247ec681f3Smrgvoid
1257ec681f3Smrgutil_init_pipe_vertex_state(struct pipe_screen *screen,
1267ec681f3Smrg                            struct pipe_vertex_buffer *buffer,
1277ec681f3Smrg                            const struct pipe_vertex_element *elements,
1287ec681f3Smrg                            unsigned num_elements,
1297ec681f3Smrg                            struct pipe_resource *indexbuf,
1307ec681f3Smrg                            uint32_t full_velem_mask,
1317ec681f3Smrg                            struct pipe_vertex_state *state);
1327ec681f3Smrg
133af69d88dSmrg#ifdef __cplusplus
134af69d88dSmrg}
135af69d88dSmrg#endif
136af69d88dSmrg
137af69d88dSmrg#endif
138