1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright © 2009 Jakob Bornecrantz 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci **************************************************************************/ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef I915_WINSYS_H 27bf215546Sopenharmony_ci#define I915_WINSYS_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_cistruct i915_winsys; 32bf215546Sopenharmony_cistruct i915_winsys_buffer; 33bf215546Sopenharmony_cistruct i915_winsys_batchbuffer; 34bf215546Sopenharmony_cistruct pipe_resource; 35bf215546Sopenharmony_cistruct pipe_fence_handle; 36bf215546Sopenharmony_cistruct winsys_handle; 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_cienum i915_winsys_buffer_usage { 39bf215546Sopenharmony_ci /* use on textures */ 40bf215546Sopenharmony_ci I915_USAGE_RENDER = 0x01, 41bf215546Sopenharmony_ci I915_USAGE_SAMPLER = 0x02, 42bf215546Sopenharmony_ci I915_USAGE_2D_TARGET = 0x04, 43bf215546Sopenharmony_ci I915_USAGE_2D_SOURCE = 0x08, 44bf215546Sopenharmony_ci /* use on vertex */ 45bf215546Sopenharmony_ci I915_USAGE_VERTEX = 0x10 46bf215546Sopenharmony_ci}; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cienum i915_winsys_buffer_type { 49bf215546Sopenharmony_ci I915_NEW_TEXTURE, 50bf215546Sopenharmony_ci I915_NEW_SCANOUT, /**< a texture used for scanning out from */ 51bf215546Sopenharmony_ci I915_NEW_VERTEX 52bf215546Sopenharmony_ci}; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci/* These need to be in sync with the definitions of libdrm-intel! */ 55bf215546Sopenharmony_cienum i915_winsys_buffer_tile { I915_TILE_NONE, I915_TILE_X, I915_TILE_Y }; 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_cienum i915_winsys_flush_flags { 58bf215546Sopenharmony_ci I915_FLUSH_ASYNC = 0, 59bf215546Sopenharmony_ci I915_FLUSH_END_OF_FRAME = 1 60bf215546Sopenharmony_ci}; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_cistruct i915_winsys_batchbuffer { 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci struct i915_winsys *iws; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci /** 67bf215546Sopenharmony_ci * Values exported to speed up the writing the batchbuffer, 68bf215546Sopenharmony_ci * instead of having to go trough a accesor function for 69bf215546Sopenharmony_ci * each dword written. 70bf215546Sopenharmony_ci */ 71bf215546Sopenharmony_ci /*{@*/ 72bf215546Sopenharmony_ci uint8_t *map; 73bf215546Sopenharmony_ci uint8_t *ptr; 74bf215546Sopenharmony_ci size_t size; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci size_t relocs; 77bf215546Sopenharmony_ci /*@}*/ 78bf215546Sopenharmony_ci}; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistruct i915_winsys { 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci unsigned pci_id; /**< PCI ID for the device */ 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci /** 85bf215546Sopenharmony_ci * Batchbuffer functions. 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_ci /*@{*/ 88bf215546Sopenharmony_ci /** 89bf215546Sopenharmony_ci * Create a new batchbuffer. 90bf215546Sopenharmony_ci */ 91bf215546Sopenharmony_ci struct i915_winsys_batchbuffer *(*batchbuffer_create)( 92bf215546Sopenharmony_ci struct i915_winsys *iws); 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci /** 95bf215546Sopenharmony_ci * Validate buffers for usage in this batchbuffer. 96bf215546Sopenharmony_ci * Does space-checking and asorted other book-keeping. 97bf215546Sopenharmony_ci * 98bf215546Sopenharmony_ci * @batch 99bf215546Sopenharmony_ci * @buffers array to buffers to validate 100bf215546Sopenharmony_ci * @num_of_buffers size of the passed array 101bf215546Sopenharmony_ci */ 102bf215546Sopenharmony_ci bool (*validate_buffers)(struct i915_winsys_batchbuffer *batch, 103bf215546Sopenharmony_ci struct i915_winsys_buffer **buffers, 104bf215546Sopenharmony_ci int num_of_buffers); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci /** 107bf215546Sopenharmony_ci * Emit a relocation to a buffer. 108bf215546Sopenharmony_ci * Target position in batchbuffer is the same as ptr. 109bf215546Sopenharmony_ci * 110bf215546Sopenharmony_ci * @batch 111bf215546Sopenharmony_ci * @reloc buffer address to be inserted into target. 112bf215546Sopenharmony_ci * @usage how is the hardware going to use the buffer. 113bf215546Sopenharmony_ci * @offset add this to the reloc buffers address 114bf215546Sopenharmony_ci * @target buffer where to write the address, null for batchbuffer. 115bf215546Sopenharmony_ci * @fenced relocation needs a fence. 116bf215546Sopenharmony_ci */ 117bf215546Sopenharmony_ci int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch, 118bf215546Sopenharmony_ci struct i915_winsys_buffer *reloc, 119bf215546Sopenharmony_ci enum i915_winsys_buffer_usage usage, 120bf215546Sopenharmony_ci unsigned offset, bool fenced); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /** 123bf215546Sopenharmony_ci * Flush a bufferbatch. 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_ci void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch, 126bf215546Sopenharmony_ci struct pipe_fence_handle **fence, 127bf215546Sopenharmony_ci enum i915_winsys_flush_flags flags); 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci /** 130bf215546Sopenharmony_ci * Destroy a batchbuffer. 131bf215546Sopenharmony_ci */ 132bf215546Sopenharmony_ci void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch); 133bf215546Sopenharmony_ci /*@}*/ 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci /** 136bf215546Sopenharmony_ci * Buffer functions. 137bf215546Sopenharmony_ci */ 138bf215546Sopenharmony_ci /*@{*/ 139bf215546Sopenharmony_ci /** 140bf215546Sopenharmony_ci * Create a buffer. 141bf215546Sopenharmony_ci */ 142bf215546Sopenharmony_ci struct i915_winsys_buffer *(*buffer_create)( 143bf215546Sopenharmony_ci struct i915_winsys *iws, unsigned size, 144bf215546Sopenharmony_ci enum i915_winsys_buffer_type type); 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci /** 147bf215546Sopenharmony_ci * Create a tiled buffer. 148bf215546Sopenharmony_ci * 149bf215546Sopenharmony_ci * *stride, height are in bytes. The winsys tries to allocate the buffer with 150bf215546Sopenharmony_ci * the tiling mode provide in *tiling. If tiling is no possible, *tiling will 151bf215546Sopenharmony_ci * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel 152bf215546Sopenharmony_ci * requirements) is always returned in *stride. 153bf215546Sopenharmony_ci */ 154bf215546Sopenharmony_ci struct i915_winsys_buffer *(*buffer_create_tiled)( 155bf215546Sopenharmony_ci struct i915_winsys *iws, unsigned *stride, unsigned height, 156bf215546Sopenharmony_ci enum i915_winsys_buffer_tile *tiling, enum i915_winsys_buffer_type type); 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /** 159bf215546Sopenharmony_ci * Creates a buffer from a handle. 160bf215546Sopenharmony_ci * Used to implement pipe_screen::resource_from_handle. 161bf215546Sopenharmony_ci * Also provides the stride information needed for the 162bf215546Sopenharmony_ci * texture via the stride argument. 163bf215546Sopenharmony_ci */ 164bf215546Sopenharmony_ci struct i915_winsys_buffer *(*buffer_from_handle)( 165bf215546Sopenharmony_ci struct i915_winsys *iws, struct winsys_handle *whandle, unsigned height, 166bf215546Sopenharmony_ci enum i915_winsys_buffer_tile *tiling, unsigned *stride); 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci /** 169bf215546Sopenharmony_ci * Used to implement pipe_screen::resource_get_handle. 170bf215546Sopenharmony_ci * The winsys might need the stride information. 171bf215546Sopenharmony_ci */ 172bf215546Sopenharmony_ci bool (*buffer_get_handle)(struct i915_winsys *iws, 173bf215546Sopenharmony_ci struct i915_winsys_buffer *buffer, 174bf215546Sopenharmony_ci struct winsys_handle *whandle, unsigned stride); 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci /** 177bf215546Sopenharmony_ci * Map a buffer. 178bf215546Sopenharmony_ci */ 179bf215546Sopenharmony_ci void *(*buffer_map)(struct i915_winsys *iws, 180bf215546Sopenharmony_ci struct i915_winsys_buffer *buffer, bool write); 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /** 183bf215546Sopenharmony_ci * Unmap a buffer. 184bf215546Sopenharmony_ci */ 185bf215546Sopenharmony_ci void (*buffer_unmap)(struct i915_winsys *iws, 186bf215546Sopenharmony_ci struct i915_winsys_buffer *buffer); 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci /** 189bf215546Sopenharmony_ci * Write to a buffer. 190bf215546Sopenharmony_ci * 191bf215546Sopenharmony_ci * Arguments follows pipe_buffer_write. 192bf215546Sopenharmony_ci */ 193bf215546Sopenharmony_ci int (*buffer_write)(struct i915_winsys *iws, struct i915_winsys_buffer *dst, 194bf215546Sopenharmony_ci size_t offset, size_t size, const void *data); 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci void (*buffer_destroy)(struct i915_winsys *iws, 197bf215546Sopenharmony_ci struct i915_winsys_buffer *buffer); 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci /** 200bf215546Sopenharmony_ci * Check if a buffer is busy. 201bf215546Sopenharmony_ci */ 202bf215546Sopenharmony_ci bool (*buffer_is_busy)(struct i915_winsys *iws, 203bf215546Sopenharmony_ci struct i915_winsys_buffer *buffer); 204bf215546Sopenharmony_ci /*@}*/ 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci /** 207bf215546Sopenharmony_ci * Fence functions. 208bf215546Sopenharmony_ci */ 209bf215546Sopenharmony_ci /*@{*/ 210bf215546Sopenharmony_ci /** 211bf215546Sopenharmony_ci * Reference fence and set ptr to fence. 212bf215546Sopenharmony_ci */ 213bf215546Sopenharmony_ci void (*fence_reference)(struct i915_winsys *iws, 214bf215546Sopenharmony_ci struct pipe_fence_handle **ptr, 215bf215546Sopenharmony_ci struct pipe_fence_handle *fence); 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci /** 218bf215546Sopenharmony_ci * Check if a fence has finished. 219bf215546Sopenharmony_ci */ 220bf215546Sopenharmony_ci int (*fence_signalled)(struct i915_winsys *iws, 221bf215546Sopenharmony_ci struct pipe_fence_handle *fence); 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_ci /** 224bf215546Sopenharmony_ci * Wait on a fence to finish. 225bf215546Sopenharmony_ci */ 226bf215546Sopenharmony_ci int (*fence_finish)(struct i915_winsys *iws, 227bf215546Sopenharmony_ci struct pipe_fence_handle *fence); 228bf215546Sopenharmony_ci /*@}*/ 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_ci /** 231bf215546Sopenharmony_ci * Retrieve the aperture size (in MiB) of the device. 232bf215546Sopenharmony_ci */ 233bf215546Sopenharmony_ci int (*aperture_size)(struct i915_winsys *iws); 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci /** 236bf215546Sopenharmony_ci * Destroy the winsys. 237bf215546Sopenharmony_ci */ 238bf215546Sopenharmony_ci void (*destroy)(struct i915_winsys *iws); 239bf215546Sopenharmony_ci}; 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci#endif 242