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 "util/u_box.h"
41 #include "pipe/p_state.h"
43 #include "st_context.h"
44 #include "st_texture.h"
45 #include "st_public.h"
47 static INLINE
struct pipe_transfer
*
48 st_cond_flush_get_tex_transfer(struct st_context
*st
,
49 struct pipe_resource
*pt
,
53 enum pipe_transfer_usage usage
,
54 unsigned int x
, unsigned int y
,
55 unsigned int w
, unsigned int h
)
57 struct pipe_context
*context
= st
->pipe
;
58 struct pipe_subresource subresource
;
61 subresource
.face
= face
;
62 subresource
.level
= level
;
64 u_box_2d_zslice(x
, y
, zslice
, w
, h
, &box
);
66 st_teximage_flush_before_map(st
, pt
, face
, level
, usage
);
68 return context
->get_transfer(context
,
75 static INLINE
struct pipe_transfer
*
76 st_no_flush_get_tex_transfer(struct st_context
*st
,
77 struct pipe_resource
*pt
,
81 enum pipe_transfer_usage usage
,
82 unsigned int x
, unsigned int y
,
83 unsigned int w
, unsigned int h
)
85 struct pipe_context
*context
= st
->pipe
;
87 struct pipe_subresource subresource
= u_subresource( face
, level
);
89 u_box_2d_zslice( x
, y
, zslice
,
93 return context
->get_transfer(context
,
102 st_cond_flush_pipe_buffer_write(struct st_context
*st
,
103 struct pipe_resource
*buf
,
108 struct pipe_context
*pipe
= st
->pipe
;
110 pipe_buffer_write(pipe
, buf
, offset
, size
, data
);
114 st_no_flush_pipe_buffer_write(struct st_context
*st
,
115 struct pipe_resource
*buf
,
120 pipe_buffer_write(st
->pipe
, buf
, offset
, size
, data
);
124 st_no_flush_pipe_buffer_write_nooverlap(struct st_context
*st
,
125 struct pipe_resource
*buf
,
130 pipe_buffer_write_nooverlap(st
->pipe
, buf
, offset
, size
, data
);
134 st_cond_flush_pipe_buffer_read(struct st_context
*st
,
135 struct pipe_resource
*buf
,
140 struct pipe_context
*pipe
= st
->pipe
;
142 if (pipe
->is_resource_referenced(pipe
, buf
, 0, 0) & PIPE_REFERENCED_FOR_WRITE
)
143 st_flush(st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
145 pipe_buffer_read(pipe
, buf
, offset
, size
, data
);
149 st_no_flush_pipe_buffer_read(struct st_context
*st
,
150 struct pipe_resource
*buf
,
155 pipe_buffer_read(st
->pipe
, buf
, offset
, size
, data
);