1848b8605Smrg/********************************************************** 2848b8605Smrg * Copyright 2008-2009 VMware, Inc. All rights reserved. 3848b8605Smrg * 4848b8605Smrg * Permission is hereby granted, free of charge, to any person 5848b8605Smrg * obtaining a copy of this software and associated documentation 6848b8605Smrg * files (the "Software"), to deal in the Software without 7848b8605Smrg * restriction, including without limitation the rights to use, copy, 8848b8605Smrg * modify, merge, publish, distribute, sublicense, and/or sell copies 9848b8605Smrg * of the Software, and to permit persons to whom the Software is 10848b8605Smrg * furnished to do so, subject to the following conditions: 11848b8605Smrg * 12848b8605Smrg * The above copyright notice and this permission notice shall be 13848b8605Smrg * included in all copies or substantial portions of the Software. 14848b8605Smrg * 15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16848b8605Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18848b8605Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19848b8605Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20848b8605Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21848b8605Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22848b8605Smrg * SOFTWARE. 23848b8605Smrg * 24848b8605Smrg **********************************************************/ 25848b8605Smrg 26848b8605Smrg#ifndef SVGA_SURFACE_H 27848b8605Smrg#define SVGA_SURFACE_H 28848b8605Smrg 29848b8605Smrg 30848b8605Smrg#include "pipe/p_compiler.h" 31848b8605Smrg#include "pipe/p_state.h" 32848b8605Smrg#include "util/u_inlines.h" 33848b8605Smrg#include "svga_screen_cache.h" 34848b8605Smrg 35848b8605Smrgstruct pipe_context; 36848b8605Smrgstruct pipe_screen; 37848b8605Smrgstruct svga_context; 38848b8605Smrgstruct svga_texture; 39848b8605Smrgstruct svga_winsys_surface; 40848b8605Smrgenum SVGA3dSurfaceFormat; 41848b8605Smrg 42848b8605Smrg 43848b8605Smrgstruct svga_surface 44848b8605Smrg{ 45848b8605Smrg struct pipe_surface base; 46848b8605Smrg 47848b8605Smrg struct svga_host_surface_cache_key key; 48b8e80941Smrg 49b8e80941Smrg /* 50b8e80941Smrg * Note that the handle may point at a secondary / backing resource 51b8e80941Smrg * created by svga_texture_view_surface() which is something other 52b8e80941Smrg * than svga_texture(base->texture)->handle. 53b8e80941Smrg */ 54848b8605Smrg struct svga_winsys_surface *handle; 55848b8605Smrg 56b8e80941Smrg unsigned real_layer; 57848b8605Smrg unsigned real_level; 58848b8605Smrg unsigned real_zslice; 59848b8605Smrg 60848b8605Smrg boolean dirty; 61b8e80941Smrg 62b8e80941Smrg /* VGPU10 */ 63b8e80941Smrg SVGA3dRenderTargetViewId view_id; 64b8e80941Smrg 65b8e80941Smrg /* 66b8e80941Smrg * As with 'handle' above, this may point to a secondary / backing resource. 67b8e80941Smrg * We can't have one resource bound as both a render target and a shader 68b8e80941Smrg * resource at the same time. But we sometimes want to do that, such as 69b8e80941Smrg * for mipmap generation where we sample from one level and render into 70b8e80941Smrg * another. 71b8e80941Smrg * In this situation, the backed surface is the render target while the 72b8e80941Smrg * original surface is the shader resource. 73b8e80941Smrg */ 74b8e80941Smrg struct svga_surface *backed; 75b8e80941Smrg unsigned age; /* timestamp when the backed resource is 76b8e80941Smrg * synced with the original resource. 77b8e80941Smrg */ 78848b8605Smrg}; 79848b8605Smrg 80848b8605Smrg 81b8e80941Smrgvoid 82b8e80941Smrgsvga_mark_surfaces_dirty(struct svga_context *svga); 83b8e80941Smrg 84848b8605Smrgextern void 85b8e80941Smrgsvga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf, 86b8e80941Smrg boolean reset); 87b8e80941Smrg 88b8e80941Smrgvoid 89b8e80941Smrgsvga_propagate_rendertargets(struct svga_context *svga); 90848b8605Smrg 91848b8605Smrgextern boolean 92848b8605Smrgsvga_surface_needs_propagation(const struct pipe_surface *surf); 93848b8605Smrg 94848b8605Smrgstruct svga_winsys_surface * 95848b8605Smrgsvga_texture_view_surface(struct svga_context *svga, 96848b8605Smrg struct svga_texture *tex, 97b8e80941Smrg unsigned bind_flags, 98b8e80941Smrg SVGA3dSurfaceAllFlags flags, 99848b8605Smrg SVGA3dSurfaceFormat format, 100848b8605Smrg unsigned start_mip, 101848b8605Smrg unsigned num_mip, 102b8e80941Smrg int layer_pick, 103b8e80941Smrg unsigned num_layers, 104848b8605Smrg int zslice_pick, 105b8e80941Smrg boolean cacheable, 106848b8605Smrg struct svga_host_surface_cache_key *key); /* OUT */ 107848b8605Smrg 108b8e80941Smrgvoid 109b8e80941Smrgsvga_texture_copy_region(struct svga_context *svga, 110b8e80941Smrg struct svga_winsys_surface *src_handle, 111b8e80941Smrg unsigned srcSubResource, 112b8e80941Smrg unsigned src_x, unsigned src_y, unsigned src_z, 113b8e80941Smrg struct svga_winsys_surface *dst_handle, 114b8e80941Smrg unsigned dstSubResource, 115b8e80941Smrg unsigned dst_x, unsigned dst_y, unsigned dst_z, 116b8e80941Smrg unsigned width, unsigned height, unsigned depth); 117848b8605Smrg 118848b8605Smrgvoid 119848b8605Smrgsvga_texture_copy_handle(struct svga_context *svga, 120848b8605Smrg struct svga_winsys_surface *src_handle, 121848b8605Smrg unsigned src_x, unsigned src_y, unsigned src_z, 122848b8605Smrg unsigned src_level, unsigned src_face, 123848b8605Smrg struct svga_winsys_surface *dst_handle, 124848b8605Smrg unsigned dst_x, unsigned dst_y, unsigned dst_z, 125848b8605Smrg unsigned dst_level, unsigned dst_face, 126848b8605Smrg unsigned width, unsigned height, unsigned depth); 127848b8605Smrg 128848b8605Smrg 129b8e80941Smrgstatic inline struct svga_surface * 130848b8605Smrgsvga_surface(struct pipe_surface *surface) 131848b8605Smrg{ 132848b8605Smrg return (struct svga_surface *)surface; 133848b8605Smrg} 134848b8605Smrg 135848b8605Smrg 136b8e80941Smrgstatic inline const struct svga_surface * 137848b8605Smrgsvga_surface_const(const struct pipe_surface *surface) 138848b8605Smrg{ 139848b8605Smrg return (const struct svga_surface *)surface; 140848b8605Smrg} 141848b8605Smrg 142b8e80941Smrgstruct pipe_surface * 143b8e80941Smrgsvga_validate_surface_view(struct svga_context *svga, struct svga_surface *s); 144b8e80941Smrg 145b8e80941Smrgstatic inline SVGA3dResourceType 146b8e80941Smrgsvga_resource_type(enum pipe_texture_target target) 147b8e80941Smrg{ 148b8e80941Smrg switch (target) { 149b8e80941Smrg case PIPE_TEXTURE_1D: 150b8e80941Smrg case PIPE_TEXTURE_1D_ARRAY: 151b8e80941Smrg return SVGA3D_RESOURCE_TEXTURE1D; 152b8e80941Smrg case PIPE_TEXTURE_RECT: 153b8e80941Smrg case PIPE_TEXTURE_2D: 154b8e80941Smrg case PIPE_TEXTURE_2D_ARRAY: 155b8e80941Smrg case PIPE_TEXTURE_CUBE: 156b8e80941Smrg case PIPE_TEXTURE_CUBE_ARRAY: 157b8e80941Smrg /* drawing to cube map is treated as drawing to 2D array */ 158b8e80941Smrg return SVGA3D_RESOURCE_TEXTURE2D; 159b8e80941Smrg case PIPE_TEXTURE_3D: 160b8e80941Smrg return SVGA3D_RESOURCE_TEXTURE3D; 161b8e80941Smrg default: 162b8e80941Smrg assert(!"Unexpected texture target"); 163b8e80941Smrg return SVGA3D_RESOURCE_TEXTURE2D; 164b8e80941Smrg } 165b8e80941Smrg} 166b8e80941Smrg 167848b8605Smrg#endif 168