13464ebd5Sriastradh/**********************************************************
23464ebd5Sriastradh * Copyright 2008-2009 VMware, Inc.  All rights reserved.
33464ebd5Sriastradh *
43464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person
53464ebd5Sriastradh * obtaining a copy of this software and associated documentation
63464ebd5Sriastradh * files (the "Software"), to deal in the Software without
73464ebd5Sriastradh * restriction, including without limitation the rights to use, copy,
83464ebd5Sriastradh * modify, merge, publish, distribute, sublicense, and/or sell copies
93464ebd5Sriastradh * of the Software, and to permit persons to whom the Software is
103464ebd5Sriastradh * furnished to do so, subject to the following conditions:
113464ebd5Sriastradh *
123464ebd5Sriastradh * The above copyright notice and this permission notice shall be
133464ebd5Sriastradh * included in all copies or substantial portions of the Software.
143464ebd5Sriastradh *
153464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
163464ebd5Sriastradh * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
173464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
183464ebd5Sriastradh * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
193464ebd5Sriastradh * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
203464ebd5Sriastradh * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
213464ebd5Sriastradh * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
223464ebd5Sriastradh * SOFTWARE.
233464ebd5Sriastradh *
243464ebd5Sriastradh **********************************************************/
253464ebd5Sriastradh
263464ebd5Sriastradh#ifndef SVGA_SURFACE_H
273464ebd5Sriastradh#define SVGA_SURFACE_H
283464ebd5Sriastradh
293464ebd5Sriastradh
303464ebd5Sriastradh#include "pipe/p_compiler.h"
313464ebd5Sriastradh#include "pipe/p_state.h"
323464ebd5Sriastradh#include "util/u_inlines.h"
333464ebd5Sriastradh#include "svga_screen_cache.h"
343464ebd5Sriastradh
353464ebd5Sriastradhstruct pipe_context;
363464ebd5Sriastradhstruct pipe_screen;
373464ebd5Sriastradhstruct svga_context;
383464ebd5Sriastradhstruct svga_texture;
393464ebd5Sriastradhstruct svga_winsys_surface;
403464ebd5Sriastradhenum SVGA3dSurfaceFormat;
413464ebd5Sriastradh
423464ebd5Sriastradh
433464ebd5Sriastradhstruct svga_surface
443464ebd5Sriastradh{
453464ebd5Sriastradh   struct pipe_surface base;
463464ebd5Sriastradh
473464ebd5Sriastradh   struct svga_host_surface_cache_key key;
4801e04c3fSmrg
4901e04c3fSmrg   /*
5001e04c3fSmrg    * Note that the handle may point at a secondary / backing resource
5101e04c3fSmrg    * created by svga_texture_view_surface() which is something other
5201e04c3fSmrg    * than svga_texture(base->texture)->handle.
5301e04c3fSmrg    */
543464ebd5Sriastradh   struct svga_winsys_surface *handle;
553464ebd5Sriastradh
5601e04c3fSmrg   unsigned real_layer;
573464ebd5Sriastradh   unsigned real_level;
583464ebd5Sriastradh   unsigned real_zslice;
593464ebd5Sriastradh
603464ebd5Sriastradh   boolean dirty;
6101e04c3fSmrg
6201e04c3fSmrg   /* VGPU10 */
6301e04c3fSmrg   SVGA3dRenderTargetViewId view_id;
6401e04c3fSmrg
6501e04c3fSmrg   /*
6601e04c3fSmrg    * As with 'handle' above, this may point to a secondary / backing resource.
6701e04c3fSmrg    * We can't have one resource bound as both a render target and a shader
6801e04c3fSmrg    * resource at the same time.  But we sometimes want to do that, such as
6901e04c3fSmrg    * for mipmap generation where we sample from one level and render into
7001e04c3fSmrg    * another.
7101e04c3fSmrg    * In this situation, the backed surface is the render target while the
7201e04c3fSmrg    * original surface is the shader resource.
7301e04c3fSmrg    */
7401e04c3fSmrg   struct svga_surface *backed;
7501e04c3fSmrg   unsigned age;                   /* timestamp when the backed resource is
7601e04c3fSmrg                                    * synced with the original resource.
7701e04c3fSmrg                                    */
783464ebd5Sriastradh};
793464ebd5Sriastradh
803464ebd5Sriastradh
8101e04c3fSmrgvoid
8201e04c3fSmrgsvga_mark_surfaces_dirty(struct svga_context *svga);
8301e04c3fSmrg
843464ebd5Sriastradhextern void
8501e04c3fSmrgsvga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
8601e04c3fSmrg                       boolean reset);
8701e04c3fSmrg
8801e04c3fSmrgvoid
8901e04c3fSmrgsvga_propagate_rendertargets(struct svga_context *svga);
903464ebd5Sriastradh
913464ebd5Sriastradhextern boolean
92af69d88dSmrgsvga_surface_needs_propagation(const struct pipe_surface *surf);
933464ebd5Sriastradh
943464ebd5Sriastradhstruct svga_winsys_surface *
953464ebd5Sriastradhsvga_texture_view_surface(struct svga_context *svga,
963464ebd5Sriastradh                          struct svga_texture *tex,
9701e04c3fSmrg                          unsigned bind_flags,
9801e04c3fSmrg                          SVGA3dSurfaceAllFlags flags,
993464ebd5Sriastradh                          SVGA3dSurfaceFormat format,
1003464ebd5Sriastradh                          unsigned start_mip,
1013464ebd5Sriastradh                          unsigned num_mip,
10201e04c3fSmrg                          int layer_pick,
10301e04c3fSmrg                          unsigned num_layers,
1043464ebd5Sriastradh                          int zslice_pick,
10501e04c3fSmrg                          boolean cacheable,
1063464ebd5Sriastradh                          struct svga_host_surface_cache_key *key); /* OUT */
1073464ebd5Sriastradh
10801e04c3fSmrgvoid
10901e04c3fSmrgsvga_texture_copy_region(struct svga_context *svga,
11001e04c3fSmrg                         struct svga_winsys_surface *src_handle,
11101e04c3fSmrg                         unsigned srcSubResource,
11201e04c3fSmrg                         unsigned src_x, unsigned src_y, unsigned src_z,
11301e04c3fSmrg                         struct svga_winsys_surface *dst_handle,
11401e04c3fSmrg                         unsigned dstSubResource,
11501e04c3fSmrg                         unsigned dst_x, unsigned dst_y, unsigned dst_z,
11601e04c3fSmrg                         unsigned width, unsigned height, unsigned depth);
1173464ebd5Sriastradh
1183464ebd5Sriastradhvoid
1193464ebd5Sriastradhsvga_texture_copy_handle(struct svga_context *svga,
1203464ebd5Sriastradh                         struct svga_winsys_surface *src_handle,
1213464ebd5Sriastradh                         unsigned src_x, unsigned src_y, unsigned src_z,
1223464ebd5Sriastradh                         unsigned src_level, unsigned src_face,
1233464ebd5Sriastradh                         struct svga_winsys_surface *dst_handle,
1243464ebd5Sriastradh                         unsigned dst_x, unsigned dst_y, unsigned dst_z,
1253464ebd5Sriastradh                         unsigned dst_level, unsigned dst_face,
1263464ebd5Sriastradh                         unsigned width, unsigned height, unsigned depth);
1273464ebd5Sriastradh
1283464ebd5Sriastradh
12901e04c3fSmrgstatic inline struct svga_surface *
1303464ebd5Sriastradhsvga_surface(struct pipe_surface *surface)
1313464ebd5Sriastradh{
1323464ebd5Sriastradh   return (struct svga_surface *)surface;
1333464ebd5Sriastradh}
1343464ebd5Sriastradh
135af69d88dSmrg
13601e04c3fSmrgstatic inline const struct svga_surface *
137af69d88dSmrgsvga_surface_const(const struct pipe_surface *surface)
138af69d88dSmrg{
139af69d88dSmrg   return (const struct svga_surface *)surface;
140af69d88dSmrg}
141af69d88dSmrg
14201e04c3fSmrgstruct pipe_surface *
14301e04c3fSmrgsvga_validate_surface_view(struct svga_context *svga, struct svga_surface *s);
14401e04c3fSmrg
14501e04c3fSmrgstatic inline SVGA3dResourceType
14601e04c3fSmrgsvga_resource_type(enum pipe_texture_target target)
14701e04c3fSmrg{
14801e04c3fSmrg   switch (target) {
1497ec681f3Smrg   case PIPE_BUFFER:
1507ec681f3Smrg      return SVGA3D_RESOURCE_BUFFER;
15101e04c3fSmrg   case PIPE_TEXTURE_1D:
15201e04c3fSmrg   case PIPE_TEXTURE_1D_ARRAY:
15301e04c3fSmrg      return SVGA3D_RESOURCE_TEXTURE1D;
15401e04c3fSmrg   case PIPE_TEXTURE_RECT:
15501e04c3fSmrg   case PIPE_TEXTURE_2D:
15601e04c3fSmrg   case PIPE_TEXTURE_2D_ARRAY:
15701e04c3fSmrg   case PIPE_TEXTURE_CUBE:
15801e04c3fSmrg   case PIPE_TEXTURE_CUBE_ARRAY:
15901e04c3fSmrg      /* drawing to cube map is treated as drawing to 2D array */
16001e04c3fSmrg      return SVGA3D_RESOURCE_TEXTURE2D;
16101e04c3fSmrg   case PIPE_TEXTURE_3D:
16201e04c3fSmrg      return SVGA3D_RESOURCE_TEXTURE3D;
16301e04c3fSmrg   default:
16401e04c3fSmrg      assert(!"Unexpected texture target");
16501e04c3fSmrg      return SVGA3D_RESOURCE_TEXTURE2D;
16601e04c3fSmrg   }
16701e04c3fSmrg}
16801e04c3fSmrg
1693464ebd5Sriastradh#endif
170