101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2014-2017 Broadcom
301e04c3fSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
401e04c3fSmrg *
501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
601e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
701e04c3fSmrg * to deal in the Software without restriction, including without limitation
801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1101e04c3fSmrg *
1201e04c3fSmrg * The above copyright notice and this permission notice (including the next
1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1401e04c3fSmrg * Software.
1501e04c3fSmrg *
1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2201e04c3fSmrg * IN THE SOFTWARE.
2301e04c3fSmrg */
2401e04c3fSmrg
257ec681f3Smrg#ifndef V3D_RESOURCE_H
267ec681f3Smrg#define V3D_RESOURCE_H
2701e04c3fSmrg
2801e04c3fSmrg#include "v3d_screen.h"
2901e04c3fSmrg#include "util/u_transfer.h"
3001e04c3fSmrg
317ec681f3Smrg#include "broadcom/common/v3d_tiling.h"
3201e04c3fSmrg
3301e04c3fSmrgstruct v3d_transfer {
3401e04c3fSmrg        struct pipe_transfer base;
3501e04c3fSmrg        void *map;
3601e04c3fSmrg};
3701e04c3fSmrg
3801e04c3fSmrgstruct v3d_resource_slice {
3901e04c3fSmrg        uint32_t offset;
4001e04c3fSmrg        uint32_t stride;
4101e04c3fSmrg        uint32_t padded_height;
4201e04c3fSmrg        /* Size of a single pane of the slice.  For 3D textures, there will be
4301e04c3fSmrg         * a number of panes equal to the minified, power-of-two-aligned
4401e04c3fSmrg         * depth.
4501e04c3fSmrg         */
4601e04c3fSmrg        uint32_t size;
4701e04c3fSmrg        uint8_t ub_pad;
4801e04c3fSmrg        enum v3d_tiling_mode tiling;
4901e04c3fSmrg};
5001e04c3fSmrg
5101e04c3fSmrgstruct v3d_surface {
5201e04c3fSmrg        struct pipe_surface base;
5301e04c3fSmrg        uint32_t offset;
5401e04c3fSmrg        enum v3d_tiling_mode tiling;
5501e04c3fSmrg        /**
5601e04c3fSmrg         * Output image format for TILE_RENDERING_MODE_CONFIGURATION
5701e04c3fSmrg         */
5801e04c3fSmrg        uint8_t format;
5901e04c3fSmrg
6001e04c3fSmrg        /**
6101e04c3fSmrg         * Internal format of the tile buffer for
6201e04c3fSmrg         * TILE_RENDERING_MODE_CONFIGURATION.
6301e04c3fSmrg         */
6401e04c3fSmrg        uint8_t internal_type;
6501e04c3fSmrg
6601e04c3fSmrg        /**
6701e04c3fSmrg         * internal bpp value (0=32bpp, 2=128bpp) for color buffers in
6801e04c3fSmrg         * TILE_RENDERING_MODE_CONFIGURATION.
6901e04c3fSmrg         */
7001e04c3fSmrg        uint8_t internal_bpp;
7101e04c3fSmrg
729f464c52Smaya        /**
739f464c52Smaya         * If the R and B channels should be swapped.  On V3D 3.x, we do it in
749f464c52Smaya         * the shader and the blend equation.  On V3D 4.1+, we can use the new
759f464c52Smaya         * TLB load/store flags instead of recompiling.
769f464c52Smaya         */
779f464c52Smaya        bool swap_rb;
789f464c52Smaya
7901e04c3fSmrg        uint32_t padded_height_of_output_image_in_uif_blocks;
8001e04c3fSmrg
8101e04c3fSmrg        /* If the resource being referenced is separate stencil, then this is
8201e04c3fSmrg         * the surface to use when reading/writing stencil.
8301e04c3fSmrg         */
8401e04c3fSmrg        struct pipe_surface *separate_stencil;
8501e04c3fSmrg};
8601e04c3fSmrg
8701e04c3fSmrgstruct v3d_resource {
8801e04c3fSmrg        struct pipe_resource base;
8901e04c3fSmrg        struct v3d_bo *bo;
909f464c52Smaya        struct renderonly_scanout *scanout;
919f464c52Smaya        struct v3d_resource_slice slices[V3D_MAX_MIP_LEVELS];
9201e04c3fSmrg        uint32_t cube_map_stride;
937ec681f3Smrg        uint32_t sand_col128_stride;
9401e04c3fSmrg        uint32_t size;
9501e04c3fSmrg        int cpp;
9601e04c3fSmrg        bool tiled;
9701e04c3fSmrg
987ec681f3Smrg        /**
997ec681f3Smrg         * Indicates if the CS has written the resource
1007ec681f3Smrg         */
1017ec681f3Smrg        bool compute_written;
1027ec681f3Smrg
10301e04c3fSmrg        /**
10401e04c3fSmrg         * Number of times the resource has been written to.
10501e04c3fSmrg         *
10601e04c3fSmrg         * This is used to track whether we need to load the surface on first
10701e04c3fSmrg         * rendering.
10801e04c3fSmrg         */
10901e04c3fSmrg        uint64_t writes;
11001e04c3fSmrg
11101e04c3fSmrg        /**
11201e04c3fSmrg         * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
11301e04c3fSmrg         * for which parts of the resource are defined.
11401e04c3fSmrg         *
11501e04c3fSmrg         * Used for avoiding fallback to quad clears for clearing just depth,
11601e04c3fSmrg         * when the stencil contents have never been initialized.  Note that
11701e04c3fSmrg         * we're lazy and fields not present in the buffer (DEPTH in a color
11801e04c3fSmrg         * buffer) may get marked.
11901e04c3fSmrg         */
12001e04c3fSmrg        uint32_t initialized_buffers;
12101e04c3fSmrg
12201e04c3fSmrg        enum pipe_format internal_format;
12301e04c3fSmrg
12401e04c3fSmrg        /* Resource storing the S8 part of a Z32F_S8 resource, or NULL. */
12501e04c3fSmrg        struct v3d_resource *separate_stencil;
12601e04c3fSmrg};
12701e04c3fSmrg
12801e04c3fSmrgstatic inline struct v3d_resource *
12901e04c3fSmrgv3d_resource(struct pipe_resource *prsc)
13001e04c3fSmrg{
13101e04c3fSmrg        return (struct v3d_resource *)prsc;
13201e04c3fSmrg}
13301e04c3fSmrg
13401e04c3fSmrgstatic inline struct v3d_surface *
13501e04c3fSmrgv3d_surface(struct pipe_surface *psurf)
13601e04c3fSmrg{
13701e04c3fSmrg        return (struct v3d_surface *)psurf;
13801e04c3fSmrg}
13901e04c3fSmrg
14001e04c3fSmrgstatic inline struct v3d_transfer *
14101e04c3fSmrgv3d_transfer(struct pipe_transfer *ptrans)
14201e04c3fSmrg{
14301e04c3fSmrg        return (struct v3d_transfer *)ptrans;
14401e04c3fSmrg}
14501e04c3fSmrg
14601e04c3fSmrgvoid v3d_resource_screen_init(struct pipe_screen *pscreen);
14701e04c3fSmrgvoid v3d_resource_context_init(struct pipe_context *pctx);
14801e04c3fSmrgstruct pipe_resource *v3d_resource_create(struct pipe_screen *pscreen,
14901e04c3fSmrg                                          const struct pipe_resource *tmpl);
1509f464c52Smayavoid v3d_update_shadow_texture(struct pipe_context *pctx,
1519f464c52Smaya                               struct pipe_sampler_view *view);
15201e04c3fSmrguint32_t v3d_layer_offset(struct pipe_resource *prsc, uint32_t level,
15301e04c3fSmrg                          uint32_t layer);
15401e04c3fSmrg
15501e04c3fSmrg
1567ec681f3Smrg#endif /* V3D_RESOURCE_H */
157