13464ebd5Sriastradh/**************************************************************************
27ec681f3Smrg *
3af69d88dSmrg * Copyright 2008 VMware, Inc.
43464ebd5Sriastradh * All Rights Reserved.
57ec681f3Smrg *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
137ec681f3Smrg *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
177ec681f3Smrg *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
193464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
223464ebd5Sriastradh * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233464ebd5Sriastradh * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243464ebd5Sriastradh * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh#ifndef I915_RESOURCE_H
293464ebd5Sriastradh#define I915_RESOURCE_H
303464ebd5Sriastradh
313464ebd5Sriastradhstruct i915_screen;
323464ebd5Sriastradh
333464ebd5Sriastradh#include "util/u_debug.h"
347ec681f3Smrg#include "util/u_transfer.h"
353464ebd5Sriastradh#include "i915_winsys.h"
363464ebd5Sriastradh
373464ebd5Sriastradhstruct i915_context;
383464ebd5Sriastradhstruct i915_screen;
393464ebd5Sriastradh
403464ebd5Sriastradhstruct i915_buffer {
417ec681f3Smrg   struct pipe_resource b;
423464ebd5Sriastradh   uint8_t *data;
437ec681f3Smrg   bool free_on_destroy;
443464ebd5Sriastradh};
453464ebd5Sriastradh
463464ebd5Sriastradh/* Texture transfer. */
473464ebd5Sriastradhstruct i915_transfer {
483464ebd5Sriastradh   /* Base class. */
493464ebd5Sriastradh   struct pipe_transfer b;
503464ebd5Sriastradh   struct pipe_resource *staging_texture;
513464ebd5Sriastradh};
523464ebd5Sriastradh
537ec681f3Smrg#define I915_MAX_TEXTURE_2D_LEVELS 12 /* max 2048x2048 */
547ec681f3Smrg#define I915_MAX_TEXTURE_3D_LEVELS 9  /* max 256x256x256 */
553464ebd5Sriastradh
563464ebd5Sriastradhstruct offset_pair {
577ec681f3Smrg   unsigned short nblocksx;
587ec681f3Smrg   unsigned short nblocksy;
593464ebd5Sriastradh};
603464ebd5Sriastradh
613464ebd5Sriastradhstruct i915_texture {
627ec681f3Smrg   struct pipe_resource b;
633464ebd5Sriastradh
643464ebd5Sriastradh   /* tiling flags */
653464ebd5Sriastradh   enum i915_winsys_buffer_tile tiling;
663464ebd5Sriastradh   unsigned stride;
677ec681f3Smrg   unsigned depth_stride; /* per-image on i945? */
683464ebd5Sriastradh   unsigned total_nblocksy;
693464ebd5Sriastradh
703464ebd5Sriastradh   unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];
713464ebd5Sriastradh
723464ebd5Sriastradh   /* Explicitly store the offset of each image for each cube face or
733464ebd5Sriastradh    * depth value.
743464ebd5Sriastradh    *
753464ebd5Sriastradh    * Array [depth] off offsets.
763464ebd5Sriastradh    */
773464ebd5Sriastradh   struct offset_pair *image_offset[I915_MAX_TEXTURE_2D_LEVELS];
783464ebd5Sriastradh
793464ebd5Sriastradh   /* The data is held here:
803464ebd5Sriastradh    */
813464ebd5Sriastradh   struct i915_winsys_buffer *buffer;
823464ebd5Sriastradh};
833464ebd5Sriastradh
847ec681f3Smrgunsigned i915_texture_offset(const struct i915_texture *tex, unsigned level,
857ec681f3Smrg                             unsigned layer);
863464ebd5Sriastradhvoid i915_init_screen_resource_functions(struct i915_screen *is);
873464ebd5Sriastradhvoid i915_init_resource_functions(struct i915_context *i915);
883464ebd5Sriastradh
897ec681f3Smrgstatic inline struct i915_texture *
907ec681f3Smrgi915_texture(struct pipe_resource *resource)
913464ebd5Sriastradh{
923464ebd5Sriastradh   struct i915_texture *tex = (struct i915_texture *)resource;
937ec681f3Smrg   assert(tex->b.target != PIPE_BUFFER);
943464ebd5Sriastradh   return tex;
953464ebd5Sriastradh}
963464ebd5Sriastradh
977ec681f3Smrgstatic inline struct i915_buffer *
987ec681f3Smrgi915_buffer(struct pipe_resource *resource)
993464ebd5Sriastradh{
1003464ebd5Sriastradh   struct i915_buffer *tex = (struct i915_buffer *)resource;
1017ec681f3Smrg   assert(tex->b.target == PIPE_BUFFER);
1023464ebd5Sriastradh   return tex;
1033464ebd5Sriastradh}
1043464ebd5Sriastradh
1057ec681f3Smrgstruct pipe_resource *i915_texture_create(struct pipe_screen *screen,
1067ec681f3Smrg                                          const struct pipe_resource *template,
1077ec681f3Smrg                                          bool force_untiled);
1087ec681f3Smrg
1097ec681f3Smrgbool i915_resource_get_handle(struct pipe_screen *screen,
1107ec681f3Smrg                              struct pipe_context *context,
1117ec681f3Smrg                              struct pipe_resource *texture,
1127ec681f3Smrg                              struct winsys_handle *whandle, unsigned usage);
1133464ebd5Sriastradh
1143464ebd5Sriastradhstruct pipe_resource *
1157ec681f3Smrgi915_texture_from_handle(struct pipe_screen *screen,
1167ec681f3Smrg                         const struct pipe_resource *template,
1177ec681f3Smrg                         struct winsys_handle *whandle);
1183464ebd5Sriastradh
1197ec681f3Smrgstruct pipe_resource *i915_user_buffer_create(struct pipe_screen *screen,
1207ec681f3Smrg                                              void *ptr, unsigned bytes,
1217ec681f3Smrg                                              unsigned usage);
1223464ebd5Sriastradh
1237ec681f3Smrgstruct pipe_resource *i915_buffer_create(struct pipe_screen *screen,
1247ec681f3Smrg                                         const struct pipe_resource *template);
1253464ebd5Sriastradh
1267ec681f3Smrgvoid i915_resource_destroy(struct pipe_screen *screen,
1277ec681f3Smrg                           struct pipe_resource *resource);
1287ec681f3Smrg
1297ec681f3Smrgvoid i915_buffer_subdata(struct pipe_context *rm_ctx,
1307ec681f3Smrg                         struct pipe_resource *resource, unsigned usage,
1317ec681f3Smrg                         unsigned offset, unsigned size, const void *data);
1327ec681f3Smrg
1337ec681f3Smrgvoid *i915_buffer_transfer_map(struct pipe_context *pipe,
1347ec681f3Smrg                               struct pipe_resource *resource, unsigned level,
1357ec681f3Smrg                               unsigned usage, const struct pipe_box *box,
1367ec681f3Smrg                               struct pipe_transfer **ptransfer);
1377ec681f3Smrg
1387ec681f3Smrgvoid i915_buffer_transfer_unmap(struct pipe_context *pipe,
1397ec681f3Smrg                                struct pipe_transfer *transfer);
1407ec681f3Smrg
1417ec681f3Smrgvoid *i915_texture_transfer_map(struct pipe_context *pipe,
1427ec681f3Smrg                                struct pipe_resource *resource, unsigned level,
1437ec681f3Smrg                                unsigned usage, const struct pipe_box *box,
1447ec681f3Smrg                                struct pipe_transfer **ptransfer);
1457ec681f3Smrg
1467ec681f3Smrgvoid i915_texture_transfer_unmap(struct pipe_context *pipe,
1477ec681f3Smrg                                 struct pipe_transfer *transfer);
1487ec681f3Smrg
1497ec681f3Smrgvoid i915_texture_subdata(struct pipe_context *pipe,
1507ec681f3Smrg                          struct pipe_resource *resource, unsigned level,
1517ec681f3Smrg                          unsigned usage, const struct pipe_box *box,
1527ec681f3Smrg                          const void *data, unsigned stride,
1537ec681f3Smrg                          unsigned layer_stride);
15401e04c3fSmrg
1553464ebd5Sriastradh#endif /* I915_RESOURCE_H */
156