2 * Copyright (c) 2012-2015 Etnaviv Project
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Wladimir J. van der Laan <laanwj@gmail.com>
27 #ifndef H_ETNAVIV_RESOURCE
28 #define H_ETNAVIV_RESOURCE
30 #include "etnaviv_internal.h"
31 #include "etnaviv_tiling.h"
32 #include "pipe/p_state.h"
33 #include "util/list.h"
35 #include "util/u_helpers.h"
41 struct etna_resource_level
{
42 unsigned width
, padded_width
; /* in pixels */
43 unsigned height
, padded_height
; /* in samples */
45 unsigned offset
; /* offset into memory area */
46 uint32_t stride
; /* row stride */
47 uint32_t layer_stride
; /* layer stride */
48 unsigned size
; /* total size of memory area */
51 uint32_t ts_layer_stride
;
53 uint32_t clear_value
; /* clear value of resource level (mainly for TS) */
56 int8_t ts_compress_fmt
; /* COLOR_COMPRESSION_FORMAT_* (-1 = disable) */
58 /* keep track if we have done some per block patching */
60 struct util_dynarray
*patch_offsets
;
63 enum etna_resource_addressing_mode
{
64 ETNA_ADDRESSING_MODE_TILED
= 0,
65 ETNA_ADDRESSING_MODE_LINEAR
,
68 /* status of queued up but not flushed reads and write operations.
69 * In _transfer_map() we need to know if queued up rendering needs
70 * to be flushed to preserve the order of cpu and gpu access. */
71 enum etna_resource_status
{
72 ETNA_PENDING_WRITE
= 0x01,
73 ETNA_PENDING_READ
= 0x02,
76 struct etna_resource
{
77 struct pipe_resource base
;
78 struct renderonly_scanout
*scanout
;
82 /* only lod 0 used for non-texture buffers */
83 /* Layout for surface (tiled, multitiled, split tiled, ...) */
84 enum etna_surface_layout layout
;
85 enum etna_resource_addressing_mode addressing_mode
;
86 /* Horizontal alignment for texture unit (TEXTURE_HALIGN_*) */
88 struct etna_bo
*bo
; /* Surface video memory */
89 struct etna_bo
*ts_bo
; /* Tile status video memory */
91 struct etna_resource_level levels
[ETNA_NUM_LOD
];
93 /* When we are rendering to a texture, we need a differently tiled resource */
94 struct pipe_resource
*texture
;
96 * If imported resources have an render/sampler incompatible tiling, we keep
97 * them as an external resource, which is blitted as needed.
99 struct pipe_resource
*external
;
101 enum etna_resource_status status
;
103 struct set
*pending_ctx
;
106 /* returns TRUE if a is newer than b */
108 etna_resource_newer(struct etna_resource
*a
, struct etna_resource
*b
)
110 return (int)(a
->seqno
- b
->seqno
) > 0;
113 /* returns TRUE if a is older than b */
115 etna_resource_older(struct etna_resource
*a
, struct etna_resource
*b
)
117 return (int)(a
->seqno
- b
->seqno
) < 0;
120 /* returns TRUE if a resource has a TS, and it is valid for at least one level */
122 etna_resource_has_valid_ts(struct etna_resource
*res
);
124 /* returns TRUE if the resource needs a resolve to itself */
126 etna_resource_needs_flush(struct etna_resource
*res
)
128 return etna_resource_has_valid_ts(res
) && ((int)(res
->seqno
- res
->flush_seqno
) > 0);
131 /* is the resource only used on the sampler? */
133 etna_resource_sampler_only(const struct pipe_resource
*pres
)
135 return (pres
->bind
& (PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
|
136 PIPE_BIND_DEPTH_STENCIL
| PIPE_BIND_BLENDABLE
)) ==
137 PIPE_BIND_SAMPLER_VIEW
;
140 static inline struct etna_resource
*
141 etna_resource(struct pipe_resource
*p
)
143 return (struct etna_resource
*)p
;
147 etna_resource_used(struct etna_context
*ctx
, struct pipe_resource
*prsc
,
148 enum etna_resource_status status
);
151 resource_read(struct etna_context
*ctx
, struct pipe_resource
*prsc
)
153 etna_resource_used(ctx
, prsc
, ETNA_PENDING_READ
);
157 resource_written(struct etna_context
*ctx
, struct pipe_resource
*prsc
)
159 etna_resource_used(ctx
, prsc
, ETNA_PENDING_WRITE
);
162 /* Allocate Tile Status for an etna resource.
163 * Tile status is a cache of the clear status per tile. This means a smaller
164 * surface has to be cleared which is faster.
165 * This is also called "fast clear". */
167 etna_screen_resource_alloc_ts(struct pipe_screen
*pscreen
,
168 struct etna_resource
*prsc
);
170 struct pipe_resource
*
171 etna_resource_alloc(struct pipe_screen
*pscreen
, unsigned layout
,
172 enum etna_resource_addressing_mode mode
, uint64_t modifier
,
173 const struct pipe_resource
*templat
);
176 etna_resource_screen_init(struct pipe_screen
*pscreen
);