2fdc7683cb82a9ff2961b12c766b86598a18ee87
[mesa.git] / src / gallium / drivers / swr / swr_resource.h
1 /****************************************************************************
2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 ***************************************************************************/
23
24 #ifndef SWR_RESOURCE_H
25 #define SWR_RESOURCE_H
26
27 #include "pipe/p_state.h"
28 #include "api.h"
29
30 struct sw_displaytarget;
31
32 enum swr_resource_status {
33 SWR_RESOURCE_UNUSED = 0x0,
34 SWR_RESOURCE_READ = 0x1,
35 SWR_RESOURCE_WRITE = 0x2,
36 };
37
38 struct swr_resource {
39 struct pipe_resource base;
40
41 bool has_depth;
42 bool has_stencil;
43
44 UINT alignedWidth;
45 UINT alignedHeight;
46
47 SWR_SURFACE_STATE swr;
48 SWR_SURFACE_STATE secondary; /* for faking depth/stencil merged formats */
49
50 struct sw_displaytarget *display_target;
51
52 unsigned row_stride[PIPE_MAX_TEXTURE_LEVELS];
53 unsigned img_stride[PIPE_MAX_TEXTURE_LEVELS];
54 unsigned mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
55
56 enum swr_resource_status status;
57
58 /* pipe_context to which resource is currently bound. */
59 struct pipe_context *bound_to_context;
60 };
61
62
63 static INLINE struct swr_resource *
64 swr_resource(struct pipe_resource *resource)
65 {
66 return (struct swr_resource *)resource;
67 }
68
69 static INLINE boolean
70 swr_resource_is_texture(const struct pipe_resource *resource)
71 {
72 switch (resource->target) {
73 case PIPE_BUFFER:
74 return FALSE;
75 case PIPE_TEXTURE_1D:
76 case PIPE_TEXTURE_1D_ARRAY:
77 case PIPE_TEXTURE_2D:
78 case PIPE_TEXTURE_2D_ARRAY:
79 case PIPE_TEXTURE_RECT:
80 case PIPE_TEXTURE_3D:
81 case PIPE_TEXTURE_CUBE:
82 case PIPE_TEXTURE_CUBE_ARRAY:
83 return TRUE;
84 default:
85 assert(0);
86 return FALSE;
87 }
88 }
89
90
91 static INLINE void *
92 swr_resource_data(struct pipe_resource *resource)
93 {
94 struct swr_resource *swr_r = swr_resource(resource);
95
96 assert(!swr_resource_is_texture(resource));
97
98 return swr_r->swr.pBaseAddress;
99 }
100
101
102 void swr_store_render_target(struct pipe_context *pipe,
103 uint32_t attachment,
104 enum SWR_TILE_STATE post_tile_state);
105
106 void swr_store_dirty_resource(struct pipe_context *pipe,
107 struct pipe_resource *resource,
108 enum SWR_TILE_STATE post_tile_state);
109
110 void swr_update_resource_status(struct pipe_context *,
111 const struct pipe_draw_info *);
112
113 /*
114 * Functions to indicate a resource's in-use status.
115 */
116 static INLINE enum
117 swr_resource_status & operator|=(enum swr_resource_status & a,
118 enum swr_resource_status b) {
119 return (enum swr_resource_status &)((int&)a |= (int)b);
120 }
121
122 static INLINE void
123 swr_resource_read(struct pipe_context *pipe, struct swr_resource *resource)
124 {
125 resource->status |= SWR_RESOURCE_READ;
126 resource->bound_to_context = pipe;
127 }
128
129 static INLINE void
130 swr_resource_write(struct pipe_context *pipe, struct swr_resource *resource)
131 {
132 resource->status |= SWR_RESOURCE_WRITE;
133 resource->bound_to_context = pipe;
134 }
135
136 static INLINE void
137 swr_resource_unused(struct pipe_context *pipe, struct swr_resource *resource)
138 {
139 resource->status = SWR_RESOURCE_UNUSED;
140 resource->bound_to_context = nullptr;
141 }
142
143 #endif