2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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, sublicense,
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 next
12 * paragraph) shall be included in all copies or substantial portions of the
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 NONINFRINGEMENT. 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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #ifndef FREEDRENO_RESOURCE_H_
28 #define FREEDRENO_RESOURCE_H_
30 #include "util/list.h"
31 #include "util/u_range.h"
32 #include "util/u_transfer_helper.h"
34 #include "freedreno_batch.h"
35 #include "freedreno_util.h"
36 #include "freedreno/fdl/freedreno_layout.h"
39 struct pipe_resource base
;
41 enum pipe_format internal_format
;
42 struct fdl_layout layout
;
44 /* buffer range that has been initialized */
45 struct util_range valid_buffer_range
;
47 struct renderonly_scanout
*scanout
;
49 /* reference to the resource holding stencil data for a z32_s8 texture */
50 /* TODO rename to secondary or auxiliary? */
51 struct fd_resource
*stencil
;
53 /* bitmask of in-flight batches which reference this resource. Note
54 * that the batch doesn't hold reference to resources (but instead
55 * the fd_ringbuffer holds refs to the underlying fd_bo), but in case
56 * the resource is destroyed we need to clean up the batch's weak
61 /* reference to batch that writes this resource: */
62 struct fd_batch
*write_batch
;
64 /* Set of batches whose batch-cache key references this resource.
65 * We need to track this to know which batch-cache entries to
66 * invalidate if, for example, the resource is invalidated or
69 uint32_t bc_batch_mask
;
71 /* Sequence # incremented each time bo changes: */
77 * TODO lrz width/height/pitch should probably also move to
81 uint16_t lrz_width
; // for lrz clear, does this differ from lrz_pitch?
87 static inline struct fd_resource
*
88 fd_resource(struct pipe_resource
*ptex
)
90 return (struct fd_resource
*)ptex
;
93 static inline const struct fd_resource
*
94 fd_resource_const(const struct pipe_resource
*ptex
)
96 return (const struct fd_resource
*)ptex
;
100 pending(struct fd_resource
*rsc
, bool write
)
102 /* if we have a pending GPU write, we are busy in any case: */
103 if (rsc
->write_batch
)
106 /* if CPU wants to write, but we are pending a GPU read, we are busy: */
107 if (write
&& rsc
->batch_mask
)
110 if (rsc
->stencil
&& pending(rsc
->stencil
, write
))
117 has_depth(enum pipe_format format
)
119 const struct util_format_description
*desc
=
120 util_format_description(format
);
121 return util_format_has_depth(desc
);
125 struct pipe_transfer base
;
126 struct pipe_resource
*staging_prsc
;
127 struct pipe_box staging_box
;
130 static inline struct fd_transfer
*
131 fd_transfer(struct pipe_transfer
*ptrans
)
133 return (struct fd_transfer
*)ptrans
;
136 static inline struct fdl_slice
*
137 fd_resource_slice(struct fd_resource
*rsc
, unsigned level
)
139 assert(level
<= rsc
->base
.last_level
);
140 return &rsc
->layout
.slices
[level
];
143 static inline uint32_t
144 fd_resource_layer_stride(struct fd_resource
*rsc
, unsigned level
)
146 return fdl_layer_stride(&rsc
->layout
, level
);
149 /* get offset for specified mipmap level and texture/array layer */
150 static inline uint32_t
151 fd_resource_offset(struct fd_resource
*rsc
, unsigned level
, unsigned layer
)
153 uint32_t offset
= fdl_surface_offset(&rsc
->layout
, level
, layer
);
154 debug_assert(offset
< fd_bo_size(rsc
->bo
));
158 static inline uint32_t
159 fd_resource_ubwc_offset(struct fd_resource
*rsc
, unsigned level
, unsigned layer
)
161 uint32_t offset
= fdl_ubwc_offset(&rsc
->layout
, level
, layer
);
162 debug_assert(offset
< fd_bo_size(rsc
->bo
));
166 /* This might be a5xx specific, but higher mipmap levels are always linear: */
168 fd_resource_level_linear(const struct pipe_resource
*prsc
, int level
)
170 struct fd_screen
*screen
= fd_screen(prsc
->screen
);
171 debug_assert(!is_a3xx(screen
));
173 return fdl_level_linear(&fd_resource_const(prsc
)->layout
, level
);
176 static inline uint32_t
177 fd_resource_tile_mode(struct pipe_resource
*prsc
, int level
)
179 return fdl_tile_mode(&fd_resource(prsc
)->layout
, level
);
183 fd_resource_ubwc_enabled(struct fd_resource
*rsc
, int level
)
185 return fdl_ubwc_enabled(&rsc
->layout
, level
);
188 /* access # of samples, with 0 normalized to 1 (which is what we care about
191 static inline unsigned
192 fd_resource_nr_samples(struct pipe_resource
*prsc
)
194 return MAX2(1, prsc
->nr_samples
);
197 void fd_resource_screen_init(struct pipe_screen
*pscreen
);
198 void fd_resource_context_init(struct pipe_context
*pctx
);
200 uint32_t fd_setup_slices(struct fd_resource
*rsc
);
201 void fd_resource_resize(struct pipe_resource
*prsc
, uint32_t sz
);
202 void fd_resource_uncompress(struct fd_context
*ctx
, struct fd_resource
*rsc
);
204 bool fd_render_condition_check(struct pipe_context
*pctx
);
206 #endif /* FREEDRENO_RESOURCE_H_ */