1 /* 2 * Copyright © 2017 Red Hat 3 * 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: 10 * 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 13 * Software. 14 * 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 21 * SOFTWARE. 22 */ 23 24 #ifndef _U_TRANSFER_HELPER_H 25 #define _U_TRANSFER_HELPER_H 26 27 #include "pipe/p_state.h" 28 #include "pipe/p_context.h" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* A helper to implement various "lowering" for transfers: 35 * 36 * - exposing separate depth and stencil resources as packed depth-stencil 37 * - MSAA resolves 38 * 39 * To use this, drivers should: 40 * 41 * 1) populate u_transfer_vtbl and plug that into pipe_screen::transfer_helper 42 * 2) plug the transfer helpers into pipe_screen/pipe_context 43 * 44 * To avoid subclassing pipe_resource (and conflicting with threaded_context) 45 * the vtbl contains setter/getter methods used for separate_stencil to access 46 * the internal_format and separate stencil buffer. 47 */ 48 49 struct u_transfer_vtbl { 50 /* NOTE I am not expecting resource_create_from_handle() or 51 * resource_create_with_modifiers() paths to be creating any 52 * resources that need special handling. Otherwise they would 53 * need to be wrapped too. 54 */ 55 struct pipe_resource * (*resource_create)(struct pipe_screen *pscreen, 56 const struct pipe_resource *templ); 57 58 void (*resource_destroy)(struct pipe_screen *pscreen, 59 struct pipe_resource *prsc); 60 61 void *(*transfer_map)(struct pipe_context *pctx, 62 struct pipe_resource *prsc, 63 unsigned level, 64 unsigned usage, 65 const struct pipe_box *box, 66 struct pipe_transfer **pptrans); 67 68 69 void (*transfer_flush_region)(struct pipe_context *pctx, 70 struct pipe_transfer *ptrans, 71 const struct pipe_box *box); 72 73 void (*transfer_unmap)(struct pipe_context *pctx, 74 struct pipe_transfer *ptrans); 75 76 /* 77 * auxiliary methods to access internal format, stencil: 78 */ 79 80 /** 81 * Must be implemented if separate stencil is used. The internal_format 82 * is the format the resource was created with. In the case of separate 83 * stencil, prsc->format is set bac to the gallium-frontend-visible format 84 * (e.g. Z32_FLOAT_S8X24_UINT) after the resource is created. 85 */ 86 enum pipe_format (*get_internal_format)(struct pipe_resource *prsc); 87 88 /** 89 * Must be implemented if separate stencil is lowered. Used to set/get 90 * the separate s8 stencil buffer. 91 * 92 * These two do not get/put references to the pipe_resource. The 93 * stencil resource will be destroyed by u_transfer_helper_resource_destroy(). 94 */ 95 void (*set_stencil)(struct pipe_resource *prsc, struct pipe_resource *stencil); 96 struct pipe_resource *(*get_stencil)(struct pipe_resource *prsc); 97 }; 98 99 enum u_transfer_helper_flags { 100 U_TRANSFER_HELPER_SEPARATE_Z32S8 = (1 << 0), 101 U_TRANSFER_HELPER_SEPARATE_STENCIL = (1 << 1), 102 U_TRANSFER_HELPER_MSAA_MAP = (1 << 3), 103 U_TRANSFER_HELPER_Z24_IN_Z32F = (1 << 4), 104 U_TRANSFER_HELPER_INTERLEAVE_IN_PLACE = (1 << 5), 105 }; 106 107 struct pipe_resource *u_transfer_helper_resource_create( 108 struct pipe_screen *pscreen, const struct pipe_resource *templ); 109 110 void u_transfer_helper_resource_destroy(struct pipe_screen *pscreen, 111 struct pipe_resource *prsc); 112 113 void *u_transfer_helper_transfer_map(struct pipe_context *pctx, 114 struct pipe_resource *prsc, 115 unsigned level, 116 unsigned usage, 117 const struct pipe_box *box, 118 struct pipe_transfer **pptrans); 119 120 121 void u_transfer_helper_transfer_flush_region(struct pipe_context *pctx, 122 struct pipe_transfer *ptrans, 123 const struct pipe_box *box); 124 125 void u_transfer_helper_transfer_unmap(struct pipe_context *pctx, 126 struct pipe_transfer *ptrans); 127 128 struct u_transfer_helper; 129 130 struct u_transfer_helper * 131 u_transfer_helper_create(const struct u_transfer_vtbl *vtbl, 132 enum u_transfer_helper_flags flags); 133 134 void u_transfer_helper_destroy(struct u_transfer_helper *helper); 135 136 #ifdef __cplusplus 137 } // extern "C" { 138 #endif 139 140 #endif /* _U_TRANSFER_HELPER_H */ 141