gallium: Create OGL state tracker wrappers for various CPU access operations.
[mesa.git] / src / mesa / state_tracker / st_inlines.h
1 #ifndef ST_INLINES_H
2 #define ST_INLINES_H
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_screen.h"
6 #include "pipe/p_defines.h"
7 #include "pipe/p_inlines.h"
8 #include "pipe/p_state.h"
9
10 #include "st_context.h"
11 #include "st_texture.h"
12 #include "st_public.h"
13
14 static INLINE struct pipe_transfer *
15 st_cond_flush_get_tex_transfer(struct st_context *st,
16 struct pipe_texture *pt,
17 unsigned int face,
18 unsigned int level,
19 unsigned int zslice,
20 enum pipe_transfer_usage usage,
21 unsigned int x, unsigned int y,
22 unsigned int w, unsigned int h)
23 {
24 struct pipe_screen *screen = st->pipe->screen;
25
26 st_teximage_flush_before_map(st, pt, face, level, usage);
27 return screen->get_tex_transfer(screen, pt, face, level, zslice, usage,
28 x, y, w, h);
29 }
30
31 static INLINE struct pipe_transfer *
32 st_no_flush_get_tex_transfer(struct st_context *st,
33 struct pipe_texture *pt,
34 unsigned int face,
35 unsigned int level,
36 unsigned int zslice,
37 enum pipe_transfer_usage usage,
38 unsigned int x, unsigned int y,
39 unsigned int w, unsigned int h)
40 {
41 struct pipe_screen *screen = st->pipe->screen;
42
43 return screen->get_tex_transfer(screen, pt, face, level,
44 zslice, usage, x, y, w, h);
45 }
46
47 static INLINE void *
48 st_cond_flush_pipe_buffer_map(struct st_context *st,
49 struct pipe_buffer *buf,
50 unsigned int map_flags)
51 {
52 struct pipe_context *pipe = st->pipe;
53 unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
54
55 if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
56 (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
57 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
58
59 return pipe_buffer_map(pipe->screen, buf, map_flags);
60 }
61
62 static INLINE void *
63 st_no_flush_pipe_buffer_map(struct st_context *st,
64 struct pipe_buffer *buf,
65 unsigned int map_flags)
66 {
67 return pipe_buffer_map(st->pipe->screen, buf, map_flags);
68 }
69
70
71 static INLINE void
72 st_cond_flush_pipe_buffer_write(struct st_context *st,
73 struct pipe_buffer *buf,
74 unsigned int offset,
75 unsigned int size,
76 const void * data)
77 {
78 struct pipe_context *pipe = st->pipe;
79
80 if (pipe->is_buffer_referenced(pipe, buf))
81 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
82
83 pipe_buffer_write(pipe->screen, buf, offset, size, data);
84 }
85
86 static INLINE void
87 st_no_flush_pipe_buffer_write(struct st_context *st,
88 struct pipe_buffer *buf,
89 unsigned int offset,
90 unsigned int size,
91 const void * data)
92 {
93 pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
94 }
95
96 static INLINE void
97 st_cond_flush_pipe_buffer_read(struct st_context *st,
98 struct pipe_buffer *buf,
99 unsigned int offset,
100 unsigned int size,
101 void * data)
102 {
103 struct pipe_context *pipe = st->pipe;
104
105 if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
106 st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
107
108 pipe_buffer_read(pipe->screen, buf, offset, size, data);
109 }
110
111 static INLINE void
112 st_no_flush_pipe_buffer_read(struct st_context *st,
113 struct pipe_buffer *buf,
114 unsigned int offset,
115 unsigned int size,
116 void * data)
117 {
118 pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
119 }
120
121 #endif
122