1848b8605Smrg/*
2848b8605Smrg * Copyright © 2014 Broadcom
3848b8605Smrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
10848b8605Smrg * Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice (including the next
13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
14848b8605Smrg * Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22848b8605Smrg * IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg#ifndef VC4_RESOURCE_H
26848b8605Smrg#define VC4_RESOURCE_H
27848b8605Smrg
28848b8605Smrg#include "vc4_screen.h"
29b8e80941Smrg#include "kernel/vc4_packet.h"
30848b8605Smrg#include "util/u_transfer.h"
31848b8605Smrg
32b8e80941Smrgstruct vc4_transfer {
33b8e80941Smrg        struct pipe_transfer base;
34b8e80941Smrg        void *map;
35b8e80941Smrg};
36b8e80941Smrg
37848b8605Smrgstruct vc4_resource_slice {
38848b8605Smrg        uint32_t offset;
39848b8605Smrg        uint32_t stride;
40b8e80941Smrg        uint32_t size;
41b8e80941Smrg        /** One of VC4_TILING_FORMAT_* */
42b8e80941Smrg        uint8_t tiling;
43848b8605Smrg};
44848b8605Smrg
45848b8605Smrgstruct vc4_surface {
46848b8605Smrg        struct pipe_surface base;
47848b8605Smrg        uint32_t offset;
48b8e80941Smrg        uint8_t tiling;
49848b8605Smrg};
50848b8605Smrg
51848b8605Smrgstruct vc4_resource {
52b8e80941Smrg        struct pipe_resource base;
53848b8605Smrg        struct vc4_bo *bo;
54b8e80941Smrg        struct renderonly_scanout *scanout;
55848b8605Smrg        struct vc4_resource_slice slices[VC4_MAX_MIP_LEVELS];
56b8e80941Smrg        uint32_t cube_map_stride;
57848b8605Smrg        int cpp;
58b8e80941Smrg        bool tiled;
59b8e80941Smrg        /** One of VC4_TEXTURE_TYPE_* */
60b8e80941Smrg        enum vc4_texture_data_type vc4_format;
61b8e80941Smrg
62b8e80941Smrg        /**
63b8e80941Smrg         * Number of times the resource has been written to.
64b8e80941Smrg         *
65b8e80941Smrg         * This is used to track when we need to update this shadow resource
66b8e80941Smrg         * from its parent in the case of GL_TEXTURE_BASE_LEVEL (which we
67b8e80941Smrg         * can't support in hardware) or GL_UNSIGNED_INTEGER index buffers.
68b8e80941Smrg         */
69b8e80941Smrg        uint64_t writes;
70b8e80941Smrg
71b8e80941Smrg        /**
72b8e80941Smrg         * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
73b8e80941Smrg         * for which parts of the resource are defined.
74b8e80941Smrg         *
75b8e80941Smrg         * Used for avoiding fallback to quad clears for clearing just depth,
76b8e80941Smrg         * when the stencil contents have never been initialized.  Note that
77b8e80941Smrg         * we're lazy and fields not present in the buffer (DEPTH in a color
78b8e80941Smrg         * buffer) may get marked.
79b8e80941Smrg         */
80b8e80941Smrg        uint32_t initialized_buffers;
81848b8605Smrg};
82848b8605Smrg
83b8e80941Smrgstatic inline struct vc4_resource *
84848b8605Smrgvc4_resource(struct pipe_resource *prsc)
85848b8605Smrg{
86848b8605Smrg        return (struct vc4_resource *)prsc;
87848b8605Smrg}
88848b8605Smrg
89b8e80941Smrgstatic inline struct vc4_surface *
90848b8605Smrgvc4_surface(struct pipe_surface *psurf)
91848b8605Smrg{
92848b8605Smrg        return (struct vc4_surface *)psurf;
93848b8605Smrg}
94848b8605Smrg
95b8e80941Smrgstatic inline struct vc4_transfer *
96b8e80941Smrgvc4_transfer(struct pipe_transfer *ptrans)
97b8e80941Smrg{
98b8e80941Smrg        return (struct vc4_transfer *)ptrans;
99b8e80941Smrg}
100b8e80941Smrg
101848b8605Smrgvoid vc4_resource_screen_init(struct pipe_screen *pscreen);
102848b8605Smrgvoid vc4_resource_context_init(struct pipe_context *pctx);
103b8e80941Smrgstruct pipe_resource *vc4_resource_create(struct pipe_screen *pscreen,
104b8e80941Smrg                                          const struct pipe_resource *tmpl);
105b8e80941Smrgvoid vc4_update_shadow_baselevel_texture(struct pipe_context *pctx,
106b8e80941Smrg                                         struct pipe_sampler_view *view);
107b8e80941Smrgstruct pipe_resource *vc4_get_shadow_index_buffer(struct pipe_context *pctx,
108b8e80941Smrg                                                  const struct pipe_draw_info *info,
109b8e80941Smrg                                                  uint32_t offset,
110b8e80941Smrg                                                  uint32_t count,
111b8e80941Smrg                                                  uint32_t *shadow_offset);
112b8e80941Smrgvoid vc4_dump_surface(struct pipe_surface *psurf);
113848b8605Smrg
114848b8605Smrg#endif /* VC4_RESOURCE_H */
115