Merge remote branch 'origin/master' into gallium_draw_llvm
[mesa.git] / src / mesa / state_tracker / st_inlines.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * Functions for checking if buffers/textures are referenced when we need
30 * to read/write from/to them. Flush when needed.
31 */
32
33 #ifndef ST_INLINES_H
34 #define ST_INLINES_H
35
36 #include "pipe/p_context.h"
37 #include "pipe/p_screen.h"
38 #include "pipe/p_defines.h"
39 #include "util/u_inlines.h"
40 #include "pipe/p_state.h"
41
42 #include "st_context.h"
43 #include "st_texture.h"
44 #include "st_public.h"
45
46 static INLINE struct pipe_transfer *
47 st_cond_flush_get_tex_transfer(struct st_context *st,
48 struct pipe_texture *pt,
49 unsigned int face,
50 unsigned int level,
51 unsigned int zslice,
52 enum pipe_transfer_usage usage,
53 unsigned int x, unsigned int y,
54 unsigned int w, unsigned int h)
55 {
56 struct pipe_context *context = st->pipe;
57
58 st_teximage_flush_before_map(st, pt, face, level, usage);
59 return context->get_tex_transfer(context, pt, face, level, zslice, usage,
60 x, y, w, h);
61 }
62
63 static INLINE struct pipe_transfer *
64 st_no_flush_get_tex_transfer(struct st_context *st,
65 struct pipe_texture *pt,
66 unsigned int face,
67 unsigned int level,
68 unsigned int zslice,
69 enum pipe_transfer_usage usage,
70 unsigned int x, unsigned int y,
71 unsigned int w, unsigned int h)
72 {
73 struct pipe_context *context = st->pipe;
74
75 return context->get_tex_transfer(context, pt, face, level,
76 zslice, usage, x, y, w, h);
77 }
78
79 static INLINE void *
80 st_cond_flush_pipe_buffer_map(struct st_context *st,
81 struct pipe_buffer *buf,
82 unsigned int map_flags)
83 {
84 struct pipe_context *pipe = st->pipe;
85 unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
86
87 if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
88 (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
89 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
90
91 return pipe_buffer_map(pipe->screen, buf, map_flags);
92 }
93
94 static INLINE void *
95 st_no_flush_pipe_buffer_map(struct st_context *st,
96 struct pipe_buffer *buf,
97 unsigned int map_flags)
98 {
99 return pipe_buffer_map(st->pipe->screen, buf, map_flags);
100 }
101
102
103 static INLINE void
104 st_cond_flush_pipe_buffer_write(struct st_context *st,
105 struct pipe_buffer *buf,
106 unsigned int offset,
107 unsigned int size,
108 const void * data)
109 {
110 struct pipe_context *pipe = st->pipe;
111
112 if (pipe->is_buffer_referenced(pipe, buf))
113 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
114
115 pipe_buffer_write(pipe->screen, buf, offset, size, data);
116 }
117
118 static INLINE void
119 st_no_flush_pipe_buffer_write(struct st_context *st,
120 struct pipe_buffer *buf,
121 unsigned int offset,
122 unsigned int size,
123 const void * data)
124 {
125 pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
126 }
127
128 static INLINE void
129 st_no_flush_pipe_buffer_write_nooverlap(struct st_context *st,
130 struct pipe_buffer *buf,
131 unsigned int offset,
132 unsigned int size,
133 const void * data)
134 {
135 pipe_buffer_write_nooverlap(st->pipe->screen, buf, offset, size, data);
136 }
137
138 static INLINE void
139 st_cond_flush_pipe_buffer_read(struct st_context *st,
140 struct pipe_buffer *buf,
141 unsigned int offset,
142 unsigned int size,
143 void * data)
144 {
145 struct pipe_context *pipe = st->pipe;
146
147 if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
148 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
149
150 pipe_buffer_read(pipe->screen, buf, offset, size, data);
151 }
152
153 static INLINE void
154 st_no_flush_pipe_buffer_read(struct st_context *st,
155 struct pipe_buffer *buf,
156 unsigned int offset,
157 unsigned int size,
158 void * data)
159 {
160 pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
161 }
162
163 #endif
164