Squashed commit of the following:
[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 "util/u_transfer.h"
7 #include "r300_screen.h"
8
9 #include "r300_winsys.h"
10 #include "r300_context.h"
11
12 #define R300_BUFFER_MAGIC 0xabcd1234
13
14 struct r300_buffer_range {
15 uint32_t start;
16 uint32_t end;
17 };
18 #define R300_BUFFER_MAX_RANGES 32
19
20 struct r300_buffer
21 {
22 struct u_resource b;
23
24 uint32_t magic;
25
26 struct r300_winsys_buffer *buf;
27
28 void *user_buffer;
29 struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES];
30 unsigned num_ranges;
31
32 void *map;
33 };
34
35 static INLINE struct r300_buffer *
36 r300_buffer(struct pipe_resource *buffer)
37 {
38 if (buffer) {
39 assert(((struct r300_buffer *)buffer)->magic == R300_BUFFER_MAGIC);
40 return (struct r300_buffer *)buffer;
41 }
42 return NULL;
43 }
44
45 static INLINE boolean
46 r300_buffer_is_user_buffer(struct pipe_resource *buffer)
47 {
48 return r300_buffer(buffer)->user_buffer ? true : false;
49 }
50
51 static INLINE boolean r300_add_buffer(struct r300_winsys_screen *rws,
52 struct pipe_resource *buffer,
53 int rd, int wr)
54 {
55 struct r300_buffer *buf = r300_buffer(buffer);
56
57 if (!buf->buf)
58 return true;
59
60 return rws->add_buffer(rws, buf->buf, rd, wr);
61 }
62
63
64 static INLINE boolean r300_add_texture(struct r300_winsys_screen *rws,
65 struct r300_texture *tex,
66 int rd, int wr)
67 {
68 return rws->add_buffer(rws, tex->buffer, rd, wr);
69 }
70
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_resource **index_buffer,
93 unsigned index_size,
94 unsigned start,
95 unsigned count);
96
97
98 struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
99 const struct pipe_resource *template);
100
101 struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen,
102 void *ptr,
103 unsigned bytes,
104 unsigned usage);
105
106 #endif