0cf349c25cdc7a6ccc6d74a4c7513bca47d1650c
[profile/ivi/mesa.git] / src / gallium / drivers / r300 / r300_screen_buffer.h
1 #ifndef R300_SCREEN_BUFFER_H
2 #define R300_SCREEN_BUFFER_H
3 #include <stdio.h>
4 #include "pipe/p_compiler.h"
5 #include "pipe/p_state.h"
6 #include "r300_screen.h"
7
8 #include "r300_winsys.h"
9 #include "r300_context.h"
10
11 #define R300_BUFFER_MAGIC 0xabcd1234
12
13 struct r300_buffer_range {
14     uint32_t start;
15     uint32_t end;
16 };
17 #define R300_BUFFER_MAX_RANGES 32
18
19 struct r300_buffer
20 {
21     struct pipe_buffer base;
22
23     uint32_t magic;
24
25     struct r300_winsys_buffer *buf;
26
27     void *user_buffer;
28     struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES];
29     unsigned num_ranges;
30
31     void *map;
32 };
33
34 static INLINE struct r300_buffer *
35 r300_buffer(struct pipe_buffer *buffer)
36 {
37     if (buffer) {
38         assert(((struct r300_buffer *)buffer)->magic == R300_BUFFER_MAGIC);
39         return (struct r300_buffer *)buffer;
40     }
41     return NULL;
42 }
43
44 static INLINE boolean 
45 r300_buffer_is_user_buffer(struct pipe_buffer *buffer)
46 {
47     return r300_buffer(buffer)->user_buffer ? true : false;
48 }
49
50 static INLINE boolean r300_add_buffer(struct r300_winsys_screen *rws,
51                                       struct pipe_buffer *buffer,
52                                       int rd, int wr)
53 {
54     struct r300_buffer *buf = r300_buffer(buffer);
55
56     if (!buf->buf)
57         return true;
58
59     return rws->add_buffer(rws, buf->buf, rd, wr);
60 }
61
62
63 static INLINE boolean r300_add_texture(struct r300_winsys_screen *rws,
64                                        struct r300_texture *tex,
65                                        int rd, int wr)
66 {
67     return rws->add_buffer(rws, tex->buffer, rd, wr);
68 }
69
70 void r300_screen_init_buffer_functions(struct r300_screen *r300screen);
71
72 static INLINE void r300_buffer_write_reloc(struct r300_winsys_screen *rws,
73                                       struct r300_buffer *buf,
74                                       uint32_t rd, uint32_t wd, uint32_t flags)
75 {
76     if (!buf->buf)
77         return;
78
79     rws->write_cs_reloc(rws, buf->buf, rd, wd, flags);
80 }
81
82 static INLINE void r300_texture_write_reloc(struct r300_winsys_screen *rws,
83                                             struct r300_texture *texture,
84                                             uint32_t rd, uint32_t wd, uint32_t flags)
85 {
86     rws->write_cs_reloc(rws, texture->buffer, rd, wd, flags);
87 }
88
89 int r300_upload_user_buffers(struct r300_context *r300);
90
91 int r300_upload_index_buffer(struct r300_context *r300,
92                              struct pipe_buffer **index_buffer,
93                              unsigned index_size,
94                              unsigned start,
95                              unsigned count);
96
97 boolean r300_buffer_is_referenced(struct r300_context *r300,
98                                   struct pipe_buffer *buf);
99 #endif