1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2008 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg#ifndef I915_RESOURCE_H 29848b8605Smrg#define I915_RESOURCE_H 30848b8605Smrg 31848b8605Smrgstruct i915_screen; 32848b8605Smrg 33848b8605Smrg#include "util/u_transfer.h" 34848b8605Smrg#include "util/u_debug.h" 35848b8605Smrg#include "i915_winsys.h" 36848b8605Smrg 37848b8605Smrg 38848b8605Smrgstruct i915_context; 39848b8605Smrgstruct i915_screen; 40848b8605Smrg 41848b8605Smrg 42848b8605Smrgstruct i915_buffer { 43848b8605Smrg struct u_resource b; 44848b8605Smrg uint8_t *data; 45848b8605Smrg boolean free_on_destroy; 46848b8605Smrg}; 47848b8605Smrg 48848b8605Smrg 49848b8605Smrg/* Texture transfer. */ 50848b8605Smrgstruct i915_transfer { 51848b8605Smrg /* Base class. */ 52848b8605Smrg struct pipe_transfer b; 53848b8605Smrg struct pipe_resource *staging_texture; 54848b8605Smrg}; 55848b8605Smrg 56848b8605Smrg 57848b8605Smrg#define I915_MAX_TEXTURE_2D_LEVELS 12 /* max 2048x2048 */ 58848b8605Smrg#define I915_MAX_TEXTURE_3D_LEVELS 9 /* max 256x256x256 */ 59848b8605Smrg 60848b8605Smrg 61848b8605Smrgstruct offset_pair { 62848b8605Smrg unsigned short nblocksx; 63848b8605Smrg unsigned short nblocksy; 64848b8605Smrg}; 65848b8605Smrg 66848b8605Smrgstruct i915_texture { 67848b8605Smrg struct u_resource b; 68848b8605Smrg 69848b8605Smrg /* tiling flags */ 70848b8605Smrg enum i915_winsys_buffer_tile tiling; 71848b8605Smrg unsigned stride; 72848b8605Smrg unsigned depth_stride; /* per-image on i945? */ 73848b8605Smrg unsigned total_nblocksy; 74848b8605Smrg 75848b8605Smrg unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS]; 76848b8605Smrg 77848b8605Smrg /* Explicitly store the offset of each image for each cube face or 78848b8605Smrg * depth value. 79848b8605Smrg * 80848b8605Smrg * Array [depth] off offsets. 81848b8605Smrg */ 82848b8605Smrg struct offset_pair *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; 83848b8605Smrg 84848b8605Smrg /* The data is held here: 85848b8605Smrg */ 86848b8605Smrg struct i915_winsys_buffer *buffer; 87848b8605Smrg}; 88848b8605Smrg 89b8e80941Smrgunsigned i915_texture_offset(const struct i915_texture *tex, 90848b8605Smrg unsigned level, unsigned layer); 91848b8605Smrgvoid i915_init_screen_resource_functions(struct i915_screen *is); 92848b8605Smrgvoid i915_init_resource_functions(struct i915_context *i915); 93848b8605Smrg 94848b8605Smrgextern struct u_resource_vtbl i915_buffer_vtbl; 95848b8605Smrgextern struct u_resource_vtbl i915_texture_vtbl; 96848b8605Smrg 97b8e80941Smrgstatic inline struct i915_texture *i915_texture(struct pipe_resource *resource) 98848b8605Smrg{ 99848b8605Smrg struct i915_texture *tex = (struct i915_texture *)resource; 100848b8605Smrg assert(tex->b.vtbl == &i915_texture_vtbl); 101848b8605Smrg return tex; 102848b8605Smrg} 103848b8605Smrg 104b8e80941Smrgstatic inline struct i915_buffer *i915_buffer(struct pipe_resource *resource) 105848b8605Smrg{ 106848b8605Smrg struct i915_buffer *tex = (struct i915_buffer *)resource; 107848b8605Smrg assert(tex->b.vtbl == &i915_buffer_vtbl); 108848b8605Smrg return tex; 109848b8605Smrg} 110848b8605Smrg 111848b8605Smrgstruct pipe_resource * 112848b8605Smrgi915_texture_create(struct pipe_screen *screen, 113848b8605Smrg const struct pipe_resource *template, 114848b8605Smrg boolean force_untiled); 115848b8605Smrg 116848b8605Smrgstruct pipe_resource * 117848b8605Smrgi915_texture_from_handle(struct pipe_screen * screen, 118848b8605Smrg const struct pipe_resource *template, 119848b8605Smrg struct winsys_handle *whandle); 120848b8605Smrg 121848b8605Smrg 122848b8605Smrgstruct pipe_resource * 123848b8605Smrgi915_user_buffer_create(struct pipe_screen *screen, 124848b8605Smrg void *ptr, 125848b8605Smrg unsigned bytes, 126848b8605Smrg unsigned usage); 127848b8605Smrg 128848b8605Smrgstruct pipe_resource * 129848b8605Smrgi915_buffer_create(struct pipe_screen *screen, 130848b8605Smrg const struct pipe_resource *template); 131848b8605Smrg 132b8e80941Smrgvoid 133b8e80941Smrgi915_buffer_subdata(struct pipe_context *rm_ctx, 134b8e80941Smrg struct pipe_resource *resource, 135b8e80941Smrg unsigned usage, unsigned offset, 136b8e80941Smrg unsigned size, const void *data); 137b8e80941Smrg 138848b8605Smrg#endif /* I915_RESOURCE_H */ 139