nir: support lowering clipdist to arrays
[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 "memory/SurfaceState.h"
28 #include "pipe/p_state.h"
29 #include "api.h"
30
31 struct sw_displaytarget;
32
33 enum swr_resource_status {
34 SWR_RESOURCE_UNUSED = 0x0,
35 SWR_RESOURCE_READ = 0x1,
36 SWR_RESOURCE_WRITE = 0x2,
37 };
38
39 struct swr_resource {
40 struct pipe_resource base;
41
42 bool has_depth;
43 bool has_stencil;
44
45 SWR_SURFACE_STATE swr;
46 SWR_SURFACE_STATE secondary; /* for faking depth/stencil merged formats */
47
48 struct sw_displaytarget *display_target;
49
50 /* If resource is multisample, then this points to a alternate resource
51 * containing the resolved multisample surface, otherwise null */
52 struct pipe_resource *resolve_target;
53
54 size_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
55 size_t secondary_mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
56
57 enum swr_resource_status status;
58
59 /* last pipe that used (validated) this resource */
60 struct pipe_context *curr_pipe;
61 };
62
63
64 static INLINE struct swr_resource *
65 swr_resource(struct pipe_resource *resource)
66 {
67 return (struct swr_resource *)resource;
68 }
69
70 static INLINE bool
71 swr_resource_is_texture(const struct pipe_resource *resource)
72 {
73 switch (resource->target) {
74 case PIPE_BUFFER:
75 return false;
76 case PIPE_TEXTURE_1D:
77 case PIPE_TEXTURE_1D_ARRAY:
78 case PIPE_TEXTURE_2D:
79 case PIPE_TEXTURE_2D_ARRAY:
80 case PIPE_TEXTURE_RECT:
81 case PIPE_TEXTURE_3D:
82 case PIPE_TEXTURE_CUBE:
83 case PIPE_TEXTURE_CUBE_ARRAY:
84 return true;
85 default:
86 assert(0);
87 return false;
88 }
89 }
90
91
92 static INLINE uint8_t *
93 swr_resource_data(struct pipe_resource *resource)
94 {
95 struct swr_resource *swr_r = swr_resource(resource);
96
97 assert(!swr_resource_is_texture(resource));
98
99 return (uint8_t*)(swr_r->swr.xpBaseAddress);
100 }
101
102
103 void swr_invalidate_render_target(struct pipe_context *pipe,
104 uint32_t attachment,
105 uint16_t width, uint16_t height);
106
107 void swr_store_render_target(struct pipe_context *pipe,
108 uint32_t attachment,
109 enum SWR_TILE_STATE post_tile_state);
110
111 void swr_store_dirty_resource(struct pipe_context *pipe,
112 struct pipe_resource *resource,
113 enum SWR_TILE_STATE post_tile_state);
114
115 void swr_update_resource_status(struct pipe_context *,
116 const struct pipe_draw_info *);
117
118 /*
119 * Functions to indicate a resource's in-use status.
120 */
121 static INLINE enum
122 swr_resource_status & operator|=(enum swr_resource_status & a,
123 enum swr_resource_status b) {
124 return (enum swr_resource_status &)((int&)a |= (int)b);
125 }
126
127 static INLINE void
128 swr_resource_read(struct pipe_resource *resource)
129 {
130 swr_resource(resource)->status |= SWR_RESOURCE_READ;
131 }
132
133 static INLINE void
134 swr_resource_write(struct pipe_resource *resource)
135 {
136 swr_resource(resource)->status |= SWR_RESOURCE_WRITE;
137 }
138
139 static INLINE void
140 swr_resource_unused(struct pipe_resource *resource)
141 {
142 swr_resource(resource)->status = SWR_RESOURCE_UNUSED;
143 }
144
145 #endif