1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Functions for checking if buffers/textures are referenced when we need
30 * to read/write from/to them. Flush when needed.
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"
42 #include "st_context.h"
43 #include "st_texture.h"
44 #include "st_public.h"
46 static INLINE
struct pipe_transfer
*
47 st_cond_flush_get_tex_transfer(struct st_context
*st
,
48 struct pipe_texture
*pt
,
52 enum pipe_transfer_usage usage
,
53 unsigned int x
, unsigned int y
,
54 unsigned int w
, unsigned int h
)
56 struct pipe_context
*context
= st
->pipe
;
58 st_teximage_flush_before_map(st
, pt
, face
, level
, usage
);
59 return context
->get_tex_transfer(context
, pt
, face
, level
, zslice
, usage
,
63 static INLINE
struct pipe_transfer
*
64 st_no_flush_get_tex_transfer(struct st_context
*st
,
65 struct pipe_texture
*pt
,
69 enum pipe_transfer_usage usage
,
70 unsigned int x
, unsigned int y
,
71 unsigned int w
, unsigned int h
)
73 struct pipe_context
*context
= st
->pipe
;
75 return context
->get_tex_transfer(context
, pt
, face
, level
,
76 zslice
, usage
, x
, y
, w
, h
);
80 st_cond_flush_pipe_buffer_map(struct st_context
*st
,
81 struct pipe_buffer
*buf
,
82 unsigned int map_flags
)
84 struct pipe_context
*pipe
= st
->pipe
;
85 unsigned int referenced
= pipe
->is_buffer_referenced(pipe
, buf
);
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
);
91 return pipe_buffer_map(pipe
->screen
, buf
, map_flags
);
95 st_no_flush_pipe_buffer_map(struct st_context
*st
,
96 struct pipe_buffer
*buf
,
97 unsigned int map_flags
)
99 return pipe_buffer_map(st
->pipe
->screen
, buf
, map_flags
);
104 st_cond_flush_pipe_buffer_write(struct st_context
*st
,
105 struct pipe_buffer
*buf
,
110 struct pipe_context
*pipe
= st
->pipe
;
112 if (pipe
->is_buffer_referenced(pipe
, buf
))
113 st_flush(st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
115 pipe_buffer_write(pipe
->screen
, buf
, offset
, size
, data
);
119 st_no_flush_pipe_buffer_write(struct st_context
*st
,
120 struct pipe_buffer
*buf
,
125 pipe_buffer_write(st
->pipe
->screen
, buf
, offset
, size
, data
);
129 st_no_flush_pipe_buffer_write_nooverlap(struct st_context
*st
,
130 struct pipe_buffer
*buf
,
135 pipe_buffer_write_nooverlap(st
->pipe
->screen
, buf
, offset
, size
, data
);
139 st_cond_flush_pipe_buffer_read(struct st_context
*st
,
140 struct pipe_buffer
*buf
,
145 struct pipe_context
*pipe
= st
->pipe
;
147 if (pipe
->is_buffer_referenced(pipe
, buf
) & PIPE_REFERENCED_FOR_WRITE
)
148 st_flush(st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
150 pipe_buffer_read(pipe
->screen
, buf
, offset
, size
, data
);
154 st_no_flush_pipe_buffer_read(struct st_context
*st
,
155 struct pipe_buffer
*buf
,
160 pipe_buffer_read(st
->pipe
->screen
, buf
, offset
, size
, data
);