Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / gallium / state_trackers / vega / 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 "vg_context.h"
37
38 #include "pipe/p_context.h"
39 #include "pipe/p_screen.h"
40 #include "pipe/p_defines.h"
41 #include "pipe/p_inlines.h"
42 #include "pipe/p_state.h"
43
44 static INLINE struct pipe_transfer *
45 st_cond_flush_get_tex_transfer(struct vg_context *st,
46 struct pipe_texture *pt,
47 unsigned int face,
48 unsigned int level,
49 unsigned int zslice,
50 enum pipe_transfer_usage usage,
51 unsigned int x, unsigned int y,
52 unsigned int w, unsigned int h)
53 {
54 struct pipe_screen *screen = st->pipe->screen;
55 struct pipe_context *pipe = st->pipe;
56 unsigned referenced =
57 pipe->is_texture_referenced(pipe, pt, face, level);
58
59 if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
60 usage == PIPE_TRANSFER_WRITE ||
61 usage == PIPE_TRANSFER_READ_WRITE))
62 vgFlush();
63
64 return screen->get_tex_transfer(screen, pt, face, level, zslice, usage,
65 x, y, w, h);
66 }
67
68 static INLINE struct pipe_transfer *
69 st_no_flush_get_tex_transfer(struct vg_context *st,
70 struct pipe_texture *pt,
71 unsigned int face,
72 unsigned int level,
73 unsigned int zslice,
74 enum pipe_transfer_usage usage,
75 unsigned int x, unsigned int y,
76 unsigned int w, unsigned int h)
77 {
78 struct pipe_screen *screen = st->pipe->screen;
79
80 return screen->get_tex_transfer(screen, pt, face, level,
81 zslice, usage, x, y, w, h);
82 }
83
84 static INLINE void *
85 st_cond_flush_pipe_buffer_map(struct vg_context *st,
86 struct pipe_buffer *buf,
87 unsigned int map_flags)
88 {
89 struct pipe_context *pipe = st->pipe;
90 unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
91
92 if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
93 (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
94 vgFlush();
95
96 return pipe_buffer_map(pipe->screen, buf, map_flags);
97 }
98
99 static INLINE void *
100 st_no_flush_pipe_buffer_map(struct vg_context *st,
101 struct pipe_buffer *buf,
102 unsigned int map_flags)
103 {
104 return pipe_buffer_map(st->pipe->screen, buf, map_flags);
105 }
106
107
108 static INLINE void
109 st_cond_flush_pipe_buffer_write(struct vg_context *st,
110 struct pipe_buffer *buf,
111 unsigned int offset,
112 unsigned int size,
113 const void * data)
114 {
115 struct pipe_context *pipe = st->pipe;
116
117 if (pipe->is_buffer_referenced(pipe, buf))
118 vgFlush();
119
120 pipe_buffer_write(pipe->screen, buf, offset, size, data);
121 }
122
123 static INLINE void
124 st_no_flush_pipe_buffer_write(struct vg_context *st,
125 struct pipe_buffer *buf,
126 unsigned int offset,
127 unsigned int size,
128 const void * data)
129 {
130 pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
131 }
132
133 static INLINE void
134 st_cond_flush_pipe_buffer_read(struct vg_context *st,
135 struct pipe_buffer *buf,
136 unsigned int offset,
137 unsigned int size,
138 void * data)
139 {
140 struct pipe_context *pipe = st->pipe;
141
142 if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
143 vgFlush();
144
145 pipe_buffer_read(pipe->screen, buf, offset, size, data);
146 }
147
148 static INLINE void
149 st_no_flush_pipe_buffer_read(struct vg_context *st,
150 struct pipe_buffer *buf,
151 unsigned int offset,
152 unsigned int size,
153 void * data)
154 {
155 pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
156 }
157
158 #endif
159