Merge branch '7.8'
[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 "util/u_box.h"
41 #include "pipe/p_state.h"
42
43 #include "st_context.h"
44 #include "st_texture.h"
45 #include "st_cb_flush.h"
46
47 static INLINE struct pipe_transfer *
48 st_cond_flush_get_tex_transfer(struct st_context *st,
49 struct pipe_resource *pt,
50 unsigned int face,
51 unsigned int level,
52 unsigned int zslice,
53 enum pipe_transfer_usage usage,
54 unsigned int x, unsigned int y,
55 unsigned int w, unsigned int h)
56 {
57 struct pipe_context *context = st->pipe;
58 struct pipe_subresource subresource;
59 struct pipe_box box;
60
61 subresource.face = face;
62 subresource.level = level;
63
64 u_box_2d_zslice(x, y, zslice, w, h, &box);
65
66 st_teximage_flush_before_map(st, pt, face, level, usage);
67
68 return context->get_transfer(context,
69 pt,
70 subresource,
71 usage,
72 &box);
73 }
74
75 static INLINE struct pipe_transfer *
76 st_no_flush_get_tex_transfer(struct st_context *st,
77 struct pipe_resource *pt,
78 unsigned int face,
79 unsigned int level,
80 unsigned int zslice,
81 enum pipe_transfer_usage usage,
82 unsigned int x, unsigned int y,
83 unsigned int w, unsigned int h)
84 {
85 struct pipe_context *context = st->pipe;
86 struct pipe_box box;
87 struct pipe_subresource subresource = u_subresource( face, level );
88
89 u_box_2d_zslice( x, y, zslice,
90 w, h,
91 &box );
92
93 return context->get_transfer(context,
94 pt,
95 subresource,
96 usage,
97 &box);
98 }
99
100
101 static INLINE void
102 st_cond_flush_pipe_buffer_write(struct st_context *st,
103 struct pipe_resource *buf,
104 unsigned int offset,
105 unsigned int size,
106 const void * data)
107 {
108 struct pipe_context *pipe = st->pipe;
109
110 pipe_buffer_write(pipe, buf, offset, size, data);
111 }
112
113 static INLINE void
114 st_no_flush_pipe_buffer_write(struct st_context *st,
115 struct pipe_resource *buf,
116 unsigned int offset,
117 unsigned int size,
118 const void * data)
119 {
120 pipe_buffer_write(st->pipe, buf, offset, size, data);
121 }
122
123 static INLINE void
124 st_no_flush_pipe_buffer_write_nooverlap(struct st_context *st,
125 struct pipe_resource *buf,
126 unsigned int offset,
127 unsigned int size,
128 const void * data)
129 {
130 pipe_buffer_write_nooverlap(st->pipe, buf, offset, size, data);
131 }
132
133 static INLINE void
134 st_cond_flush_pipe_buffer_read(struct st_context *st,
135 struct pipe_resource *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_resource_referenced(pipe, buf, 0, 0) & PIPE_REFERENCED_FOR_WRITE)
143 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
144
145 pipe_buffer_read(pipe, buf, offset, size, data);
146 }
147
148 static INLINE void
149 st_no_flush_pipe_buffer_read(struct st_context *st,
150 struct pipe_resource *buf,
151 unsigned int offset,
152 unsigned int size,
153 void * data)
154 {
155 pipe_buffer_read(st->pipe, buf, offset, size, data);
156 }
157
158 #endif
159