freedreno: move more batch related tracking to fd_batch
[mesa.git] / src / gallium / drivers / freedreno / freedreno_resource.h
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #ifndef FREEDRENO_RESOURCE_H_
30 #define FREEDRENO_RESOURCE_H_
31
32 #include "util/list.h"
33 #include "util/u_range.h"
34 #include "util/u_transfer.h"
35
36 #include "freedreno_batch.h"
37 #include "freedreno_util.h"
38
39 /* Texture Layout on a3xx:
40 *
41 * Each mipmap-level contains all of it's layers (ie. all cubmap
42 * faces, all 1d/2d array elements, etc). The texture sampler is
43 * programmed with the start address of each mipmap level, and hw
44 * derives the layer offset within the level.
45 *
46 * Texture Layout on a4xx:
47 *
48 * For cubemap and 2d array, each layer contains all of it's mipmap
49 * levels (layer_first layout).
50 *
51 * 3d textures are layed out as on a3xx, but unknown about 3d-array
52 * textures.
53 *
54 * In either case, the slice represents the per-miplevel information,
55 * but in layer_first layout it only includes the first layer, and
56 * an additional offset of (rsc->layer_size * layer) must be added.
57 */
58 struct fd_resource_slice {
59 uint32_t offset; /* offset of first layer in slice */
60 uint32_t pitch;
61 uint32_t size0; /* size of first layer in slice */
62 };
63
64 /* status of queued up but not flushed reads and write operations.
65 * In _transfer_map() we need to know if queued up rendering needs
66 * to be flushed to preserve the order of cpu and gpu access.
67 */
68 enum fd_resource_status {
69 FD_PENDING_WRITE = 0x01,
70 FD_PENDING_READ = 0x02,
71 };
72
73 struct fd_resource {
74 struct u_resource base;
75 struct fd_bo *bo;
76 uint32_t cpp;
77 enum pipe_format internal_format;
78 bool layer_first; /* see above description */
79 uint32_t layer_size;
80 struct fd_resource_slice slices[MAX_MIP_LEVELS];
81 uint32_t timestamp;
82 /* buffer range that has been initialized */
83 struct util_range valid_buffer_range;
84
85 /* reference to the resource holding stencil data for a z32_s8 texture */
86 /* TODO rename to secondary or auxiliary? */
87 struct fd_resource *stencil;
88
89 /* pending read/write state: */
90 enum fd_resource_status status;
91 /* resources accessed by queued but not flushed draws are tracked
92 * in the used_resources list.
93 */
94 struct list_head list;
95 struct fd_batch *pending_batch;
96 };
97
98 static inline struct fd_resource *
99 fd_resource(struct pipe_resource *ptex)
100 {
101 return (struct fd_resource *)ptex;
102 }
103
104 struct fd_transfer {
105 struct pipe_transfer base;
106 void *staging;
107 };
108
109 static inline struct fd_transfer *
110 fd_transfer(struct pipe_transfer *ptrans)
111 {
112 return (struct fd_transfer *)ptrans;
113 }
114
115 static inline struct fd_resource_slice *
116 fd_resource_slice(struct fd_resource *rsc, unsigned level)
117 {
118 assert(level <= rsc->base.b.last_level);
119 return &rsc->slices[level];
120 }
121
122 /* get offset for specified mipmap level and texture/array layer */
123 static inline uint32_t
124 fd_resource_offset(struct fd_resource *rsc, unsigned level, unsigned layer)
125 {
126 struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
127 unsigned offset;
128 if (rsc->layer_first) {
129 offset = slice->offset + (rsc->layer_size * layer);
130 } else {
131 offset = slice->offset + (slice->size0 * layer);
132 }
133 debug_assert(offset < fd_bo_size(rsc->bo));
134 return offset;
135 }
136
137 void fd_resource_screen_init(struct pipe_screen *pscreen);
138 void fd_resource_context_init(struct pipe_context *pctx);
139
140 bool fd_render_condition_check(struct pipe_context *pctx);
141
142 #endif /* FREEDRENO_RESOURCE_H_ */