1/* 2 * Copyright © 2014-2017 Broadcom 3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25#ifndef V3D_RESOURCE_H 26#define V3D_RESOURCE_H 27 28#include "v3d_screen.h" 29#include "util/u_transfer.h" 30 31#include "broadcom/common/v3d_tiling.h" 32 33struct v3d_transfer { 34 struct pipe_transfer base; 35 void *map; 36}; 37 38struct v3d_resource_slice { 39 uint32_t offset; 40 uint32_t stride; 41 uint32_t padded_height; 42 /* Size of a single pane of the slice. For 3D textures, there will be 43 * a number of panes equal to the minified, power-of-two-aligned 44 * depth. 45 */ 46 uint32_t size; 47 uint8_t ub_pad; 48 enum v3d_tiling_mode tiling; 49}; 50 51struct v3d_surface { 52 struct pipe_surface base; 53 uint32_t offset; 54 enum v3d_tiling_mode tiling; 55 /** 56 * Output image format for TILE_RENDERING_MODE_CONFIGURATION 57 */ 58 uint8_t format; 59 60 /** 61 * Internal format of the tile buffer for 62 * TILE_RENDERING_MODE_CONFIGURATION. 63 */ 64 uint8_t internal_type; 65 66 /** 67 * internal bpp value (0=32bpp, 2=128bpp) for color buffers in 68 * TILE_RENDERING_MODE_CONFIGURATION. 69 */ 70 uint8_t internal_bpp; 71 72 /** 73 * If the R and B channels should be swapped. On V3D 3.x, we do it in 74 * the shader and the blend equation. On V3D 4.1+, we can use the new 75 * TLB load/store flags instead of recompiling. 76 */ 77 bool swap_rb; 78 79 uint32_t padded_height_of_output_image_in_uif_blocks; 80 81 /* If the resource being referenced is separate stencil, then this is 82 * the surface to use when reading/writing stencil. 83 */ 84 struct pipe_surface *separate_stencil; 85}; 86 87struct v3d_resource { 88 struct pipe_resource base; 89 struct v3d_bo *bo; 90 struct renderonly_scanout *scanout; 91 struct v3d_resource_slice slices[V3D_MAX_MIP_LEVELS]; 92 uint32_t cube_map_stride; 93 uint32_t sand_col128_stride; 94 uint32_t size; 95 int cpp; 96 bool tiled; 97 98 /** 99 * Indicates if the CS has written the resource 100 */ 101 bool compute_written; 102 103 /** 104 * Number of times the resource has been written to. 105 * 106 * This is used to track whether we need to load the surface on first 107 * rendering. 108 */ 109 uint64_t writes; 110 111 /** 112 * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL 113 * for which parts of the resource are defined. 114 * 115 * Used for avoiding fallback to quad clears for clearing just depth, 116 * when the stencil contents have never been initialized. Note that 117 * we're lazy and fields not present in the buffer (DEPTH in a color 118 * buffer) may get marked. 119 */ 120 uint32_t initialized_buffers; 121 122 /** 123 * A serial ID that is incremented every time a new BO is bound to a 124 * resource. We use this to track scenarios where we might need to 125 * update other resources to point to the new BO (like sampler states 126 * when a texture BO changes). 127 */ 128 uint32_t serial_id; 129 130 enum pipe_format internal_format; 131 132 /* Resource storing the S8 part of a Z32F_S8 resource, or NULL. */ 133 struct v3d_resource *separate_stencil; 134}; 135 136static inline struct v3d_resource * 137v3d_resource(struct pipe_resource *prsc) 138{ 139 return (struct v3d_resource *)prsc; 140} 141 142static inline struct v3d_surface * 143v3d_surface(struct pipe_surface *psurf) 144{ 145 return (struct v3d_surface *)psurf; 146} 147 148static inline struct v3d_transfer * 149v3d_transfer(struct pipe_transfer *ptrans) 150{ 151 return (struct v3d_transfer *)ptrans; 152} 153 154void v3d_resource_screen_init(struct pipe_screen *pscreen); 155void v3d_resource_context_init(struct pipe_context *pctx); 156struct pipe_resource *v3d_resource_create(struct pipe_screen *pscreen, 157 const struct pipe_resource *tmpl); 158void v3d_update_shadow_texture(struct pipe_context *pctx, 159 struct pipe_sampler_view *view); 160uint32_t v3d_layer_offset(struct pipe_resource *prsc, uint32_t level, 161 uint32_t layer); 162 163 164#endif /* V3D_RESOURCE_H */ 165