1af69d88dSmrg/*
2af69d88dSmrg * Copyright © 2014 Broadcom
3af69d88dSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4af69d88dSmrg *
5af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
6af69d88dSmrg * copy of this software and associated documentation files (the "Software"),
7af69d88dSmrg * to deal in the Software without restriction, including without limitation
8af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the
10af69d88dSmrg * Software is furnished to do so, subject to the following conditions:
11af69d88dSmrg *
12af69d88dSmrg * The above copyright notice and this permission notice (including the next
13af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the
14af69d88dSmrg * Software.
15af69d88dSmrg *
16af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21af69d88dSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22af69d88dSmrg * IN THE SOFTWARE.
23af69d88dSmrg */
24af69d88dSmrg
25af69d88dSmrg#ifndef VC4_RESOURCE_H
26af69d88dSmrg#define VC4_RESOURCE_H
27af69d88dSmrg
28af69d88dSmrg#include "vc4_screen.h"
2901e04c3fSmrg#include "kernel/vc4_packet.h"
30af69d88dSmrg#include "util/u_transfer.h"
31af69d88dSmrg
3201e04c3fSmrgstruct vc4_transfer {
3301e04c3fSmrg        struct pipe_transfer base;
3401e04c3fSmrg        void *map;
3501e04c3fSmrg};
3601e04c3fSmrg
37af69d88dSmrgstruct vc4_resource_slice {
38af69d88dSmrg        uint32_t offset;
39af69d88dSmrg        uint32_t stride;
4001e04c3fSmrg        uint32_t size;
4101e04c3fSmrg        /** One of VC4_TILING_FORMAT_* */
4201e04c3fSmrg        uint8_t tiling;
43af69d88dSmrg};
44af69d88dSmrg
45af69d88dSmrgstruct vc4_surface {
46af69d88dSmrg        struct pipe_surface base;
47af69d88dSmrg        uint32_t offset;
4801e04c3fSmrg        uint8_t tiling;
49af69d88dSmrg};
50af69d88dSmrg
51af69d88dSmrgstruct vc4_resource {
5201e04c3fSmrg        struct pipe_resource base;
53af69d88dSmrg        struct vc4_bo *bo;
5401e04c3fSmrg        struct renderonly_scanout *scanout;
55af69d88dSmrg        struct vc4_resource_slice slices[VC4_MAX_MIP_LEVELS];
5601e04c3fSmrg        uint32_t cube_map_stride;
57af69d88dSmrg        int cpp;
5801e04c3fSmrg        bool tiled;
5901e04c3fSmrg        /** One of VC4_TEXTURE_TYPE_* */
6001e04c3fSmrg        enum vc4_texture_data_type vc4_format;
6101e04c3fSmrg
6201e04c3fSmrg        /**
6301e04c3fSmrg         * Number of times the resource has been written to.
6401e04c3fSmrg         *
6501e04c3fSmrg         * This is used to track when we need to update this shadow resource
6601e04c3fSmrg         * from its parent in the case of GL_TEXTURE_BASE_LEVEL (which we
6701e04c3fSmrg         * can't support in hardware) or GL_UNSIGNED_INTEGER index buffers.
6801e04c3fSmrg         */
6901e04c3fSmrg        uint64_t writes;
7001e04c3fSmrg
7101e04c3fSmrg        /**
7201e04c3fSmrg         * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
7301e04c3fSmrg         * for which parts of the resource are defined.
7401e04c3fSmrg         *
7501e04c3fSmrg         * Used for avoiding fallback to quad clears for clearing just depth,
7601e04c3fSmrg         * when the stencil contents have never been initialized.  Note that
7701e04c3fSmrg         * we're lazy and fields not present in the buffer (DEPTH in a color
7801e04c3fSmrg         * buffer) may get marked.
7901e04c3fSmrg         */
8001e04c3fSmrg        uint32_t initialized_buffers;
81af69d88dSmrg};
82af69d88dSmrg
8301e04c3fSmrgstatic inline struct vc4_resource *
84af69d88dSmrgvc4_resource(struct pipe_resource *prsc)
85af69d88dSmrg{
86af69d88dSmrg        return (struct vc4_resource *)prsc;
87af69d88dSmrg}
88af69d88dSmrg
8901e04c3fSmrgstatic inline struct vc4_surface *
90af69d88dSmrgvc4_surface(struct pipe_surface *psurf)
91af69d88dSmrg{
92af69d88dSmrg        return (struct vc4_surface *)psurf;
93af69d88dSmrg}
94af69d88dSmrg
9501e04c3fSmrgstatic inline struct vc4_transfer *
9601e04c3fSmrgvc4_transfer(struct pipe_transfer *ptrans)
9701e04c3fSmrg{
9801e04c3fSmrg        return (struct vc4_transfer *)ptrans;
9901e04c3fSmrg}
10001e04c3fSmrg
101af69d88dSmrgvoid vc4_resource_screen_init(struct pipe_screen *pscreen);
102af69d88dSmrgvoid vc4_resource_context_init(struct pipe_context *pctx);
10301e04c3fSmrgstruct pipe_resource *vc4_resource_create(struct pipe_screen *pscreen,
10401e04c3fSmrg                                          const struct pipe_resource *tmpl);
10501e04c3fSmrgvoid vc4_update_shadow_baselevel_texture(struct pipe_context *pctx,
10601e04c3fSmrg                                         struct pipe_sampler_view *view);
10701e04c3fSmrgstruct pipe_resource *vc4_get_shadow_index_buffer(struct pipe_context *pctx,
10801e04c3fSmrg                                                  const struct pipe_draw_info *info,
10901e04c3fSmrg                                                  uint32_t offset,
11001e04c3fSmrg                                                  uint32_t count,
11101e04c3fSmrg                                                  uint32_t *shadow_offset);
11201e04c3fSmrgvoid vc4_dump_surface(struct pipe_surface *psurf);
113af69d88dSmrg
114af69d88dSmrg#endif /* VC4_RESOURCE_H */
115