1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef I915_RESOURCE_H
29bf215546Sopenharmony_ci#define I915_RESOURCE_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_cistruct i915_screen;
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "util/u_debug.h"
34bf215546Sopenharmony_ci#include "util/u_transfer.h"
35bf215546Sopenharmony_ci#include "i915_winsys.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistruct i915_context;
38bf215546Sopenharmony_cistruct i915_screen;
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct i915_buffer {
41bf215546Sopenharmony_ci   struct pipe_resource b;
42bf215546Sopenharmony_ci   uint8_t *data;
43bf215546Sopenharmony_ci   bool free_on_destroy;
44bf215546Sopenharmony_ci};
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci/* Texture transfer. */
47bf215546Sopenharmony_cistruct i915_transfer {
48bf215546Sopenharmony_ci   /* Base class. */
49bf215546Sopenharmony_ci   struct pipe_transfer b;
50bf215546Sopenharmony_ci   struct pipe_resource *staging_texture;
51bf215546Sopenharmony_ci};
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci#define I915_MAX_TEXTURE_2D_LEVELS 12 /* max 2048x2048 */
54bf215546Sopenharmony_ci#define I915_MAX_TEXTURE_3D_LEVELS 9  /* max 256x256x256 */
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_cistruct offset_pair {
57bf215546Sopenharmony_ci   unsigned short nblocksx;
58bf215546Sopenharmony_ci   unsigned short nblocksy;
59bf215546Sopenharmony_ci};
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistruct i915_texture {
62bf215546Sopenharmony_ci   struct pipe_resource b;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   /* tiling flags */
65bf215546Sopenharmony_ci   enum i915_winsys_buffer_tile tiling;
66bf215546Sopenharmony_ci   unsigned stride;
67bf215546Sopenharmony_ci   unsigned depth_stride; /* per-image on i945? */
68bf215546Sopenharmony_ci   unsigned total_nblocksy;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   /* Explicitly store the offset of each image for each cube face or
73bf215546Sopenharmony_ci    * depth value.
74bf215546Sopenharmony_ci    *
75bf215546Sopenharmony_ci    * Array [depth] off offsets.
76bf215546Sopenharmony_ci    */
77bf215546Sopenharmony_ci   struct offset_pair *image_offset[I915_MAX_TEXTURE_2D_LEVELS];
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   /* The data is held here:
80bf215546Sopenharmony_ci    */
81bf215546Sopenharmony_ci   struct i915_winsys_buffer *buffer;
82bf215546Sopenharmony_ci};
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ciunsigned i915_texture_offset(const struct i915_texture *tex, unsigned level,
85bf215546Sopenharmony_ci                             unsigned layer);
86bf215546Sopenharmony_civoid i915_init_screen_resource_functions(struct i915_screen *is);
87bf215546Sopenharmony_civoid i915_init_resource_functions(struct i915_context *i915);
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_cistatic inline struct i915_texture *
90bf215546Sopenharmony_cii915_texture(struct pipe_resource *resource)
91bf215546Sopenharmony_ci{
92bf215546Sopenharmony_ci   struct i915_texture *tex = (struct i915_texture *)resource;
93bf215546Sopenharmony_ci   assert(tex->b.target != PIPE_BUFFER);
94bf215546Sopenharmony_ci   return tex;
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistatic inline struct i915_buffer *
98bf215546Sopenharmony_cii915_buffer(struct pipe_resource *resource)
99bf215546Sopenharmony_ci{
100bf215546Sopenharmony_ci   struct i915_buffer *tex = (struct i915_buffer *)resource;
101bf215546Sopenharmony_ci   assert(tex->b.target == PIPE_BUFFER);
102bf215546Sopenharmony_ci   return tex;
103bf215546Sopenharmony_ci}
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_cistruct pipe_resource *i915_texture_create(struct pipe_screen *screen,
106bf215546Sopenharmony_ci                                          const struct pipe_resource *template,
107bf215546Sopenharmony_ci                                          bool force_untiled);
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_cibool i915_resource_get_handle(struct pipe_screen *screen,
110bf215546Sopenharmony_ci                              struct pipe_context *context,
111bf215546Sopenharmony_ci                              struct pipe_resource *texture,
112bf215546Sopenharmony_ci                              struct winsys_handle *whandle, unsigned usage);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_cistruct pipe_resource *
115bf215546Sopenharmony_cii915_texture_from_handle(struct pipe_screen *screen,
116bf215546Sopenharmony_ci                         const struct pipe_resource *template,
117bf215546Sopenharmony_ci                         struct winsys_handle *whandle);
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_cistruct pipe_resource *i915_user_buffer_create(struct pipe_screen *screen,
120bf215546Sopenharmony_ci                                              void *ptr, unsigned bytes,
121bf215546Sopenharmony_ci                                              unsigned usage);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct pipe_resource *i915_buffer_create(struct pipe_screen *screen,
124bf215546Sopenharmony_ci                                         const struct pipe_resource *template);
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_civoid i915_resource_destroy(struct pipe_screen *screen,
127bf215546Sopenharmony_ci                           struct pipe_resource *resource);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_civoid i915_buffer_subdata(struct pipe_context *rm_ctx,
130bf215546Sopenharmony_ci                         struct pipe_resource *resource, unsigned usage,
131bf215546Sopenharmony_ci                         unsigned offset, unsigned size, const void *data);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_civoid *i915_buffer_transfer_map(struct pipe_context *pipe,
134bf215546Sopenharmony_ci                               struct pipe_resource *resource, unsigned level,
135bf215546Sopenharmony_ci                               unsigned usage, const struct pipe_box *box,
136bf215546Sopenharmony_ci                               struct pipe_transfer **ptransfer);
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_civoid i915_buffer_transfer_unmap(struct pipe_context *pipe,
139bf215546Sopenharmony_ci                                struct pipe_transfer *transfer);
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_civoid *i915_texture_transfer_map(struct pipe_context *pipe,
142bf215546Sopenharmony_ci                                struct pipe_resource *resource, unsigned level,
143bf215546Sopenharmony_ci                                unsigned usage, const struct pipe_box *box,
144bf215546Sopenharmony_ci                                struct pipe_transfer **ptransfer);
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_civoid i915_texture_transfer_unmap(struct pipe_context *pipe,
147bf215546Sopenharmony_ci                                 struct pipe_transfer *transfer);
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_civoid i915_texture_subdata(struct pipe_context *pipe,
150bf215546Sopenharmony_ci                          struct pipe_resource *resource, unsigned level,
151bf215546Sopenharmony_ci                          unsigned usage, const struct pipe_box *box,
152bf215546Sopenharmony_ci                          const void *data, unsigned stride,
153bf215546Sopenharmony_ci                          unsigned layer_stride);
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci#endif /* I915_RESOURCE_H */
156