1af69d88dSmrg/*
2af69d88dSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
3af69d88dSmrg *
4af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
5af69d88dSmrg * copy of this software and associated documentation files (the "Software"),
6af69d88dSmrg * to deal in the Software without restriction, including without limitation
7af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the
9af69d88dSmrg * Software is furnished to do so, subject to the following conditions:
10af69d88dSmrg *
11af69d88dSmrg * The above copyright notice and this permission notice (including the next
12af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the
13af69d88dSmrg * Software.
14af69d88dSmrg *
15af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20af69d88dSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21af69d88dSmrg * SOFTWARE.
22af69d88dSmrg *
23af69d88dSmrg * Authors:
24af69d88dSmrg *    Rob Clark <robclark@freedesktop.org>
25af69d88dSmrg */
26af69d88dSmrg
27af69d88dSmrg#ifndef FREEDRENO_GMEM_H_
28af69d88dSmrg#define FREEDRENO_GMEM_H_
29af69d88dSmrg
307ec681f3Smrg#include "pipe/p_state.h"
317ec681f3Smrg#include "util/list.h"
32af69d88dSmrg
3301e04c3fSmrg#include "freedreno_util.h"
3401e04c3fSmrg
35af69d88dSmrg/* per-pipe configuration for hw binning: */
36af69d88dSmrgstruct fd_vsc_pipe {
377ec681f3Smrg   uint8_t x, y, w, h; /* VSC_PIPE[p].CONFIG */
38af69d88dSmrg};
39af69d88dSmrg
40af69d88dSmrg/* per-tile configuration for hw binning: */
41af69d88dSmrgstruct fd_tile {
427ec681f3Smrg   uint8_t p; /* index into vsc_pipe[]s */
437ec681f3Smrg   uint8_t n; /* slot within pipe */
447ec681f3Smrg   uint16_t bin_w, bin_h;
457ec681f3Smrg   uint16_t xoff, yoff;
46af69d88dSmrg};
47af69d88dSmrg
48af69d88dSmrgstruct fd_gmem_stateobj {
497ec681f3Smrg   struct pipe_reference reference;
507ec681f3Smrg   struct fd_screen *screen;
517ec681f3Smrg   void *key;
527ec681f3Smrg
537ec681f3Smrg   uint32_t cbuf_base[MAX_RENDER_TARGETS];
547ec681f3Smrg   uint32_t zsbuf_base[2];
557ec681f3Smrg   uint8_t cbuf_cpp[MAX_RENDER_TARGETS];
567ec681f3Smrg   uint8_t zsbuf_cpp[2];
577ec681f3Smrg   uint16_t bin_h, nbins_y;
587ec681f3Smrg   uint16_t bin_w, nbins_x;
597ec681f3Smrg   uint16_t minx, miny;
607ec681f3Smrg   uint16_t width, height;
617ec681f3Smrg   uint16_t maxpw, maxph; /* maximum pipe width/height */
627ec681f3Smrg   uint8_t num_vsc_pipes; /* number of pipes for a20x */
637ec681f3Smrg
647ec681f3Smrg   struct fd_vsc_pipe vsc_pipe[32];
657ec681f3Smrg   struct fd_tile tile[2048];
667ec681f3Smrg
677ec681f3Smrg   struct list_head node;
687ec681f3Smrg};
697ec681f3Smrg
707ec681f3Smrgvoid __fd_gmem_destroy(struct fd_gmem_stateobj *gmem);
717ec681f3Smrg
727ec681f3Smrgstatic inline void
737ec681f3Smrgfd_gmem_reference(struct fd_gmem_stateobj **ptr, struct fd_gmem_stateobj *gmem)
747ec681f3Smrg{
757ec681f3Smrg   struct fd_gmem_stateobj *old_gmem = *ptr;
767ec681f3Smrg
777ec681f3Smrg   if (pipe_reference(&(*ptr)->reference, &gmem->reference))
787ec681f3Smrg      __fd_gmem_destroy(old_gmem);
797ec681f3Smrg
807ec681f3Smrg   *ptr = gmem;
817ec681f3Smrg}
827ec681f3Smrg
837ec681f3Smrgstruct fd_gmem_cache {
847ec681f3Smrg   struct hash_table *ht;
857ec681f3Smrg   struct list_head lru;
86af69d88dSmrg};
87af69d88dSmrg
8801e04c3fSmrgstruct fd_batch;
89af69d88dSmrg
907ec681f3Smrgvoid fd_gmem_render_tiles(struct fd_batch *batch) assert_dt;
917ec681f3Smrgunsigned fd_gmem_estimate_bins_per_pipe(struct fd_batch *batch);
927ec681f3Smrgbool fd_gmem_needs_restore(struct fd_batch *batch, const struct fd_tile *tile,
937ec681f3Smrg                           uint32_t buffers);
94af69d88dSmrg
957ec681f3Smrgstruct pipe_screen;
967ec681f3Smrgvoid fd_gmem_screen_init(struct pipe_screen *pscreen);
977ec681f3Smrgvoid fd_gmem_screen_fini(struct pipe_screen *pscreen);
98af69d88dSmrg
99af69d88dSmrg#endif /* FREEDRENO_GMEM_H_ */
100