2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 #include "radeon_r300.h"
24 #include "radeon_buffer.h"
26 #include "radeon_cs_gem.h"
28 static void radeon_set_flush_cb(struct radeon_winsys
*winsys
,
29 void (*flush_cb
)(void *),
32 winsys
->priv
->flush_cb
= flush_cb
;
33 winsys
->priv
->flush_data
= data
;
34 radeon_cs_space_set_flush(winsys
->priv
->cs
, flush_cb
, data
);
37 static boolean
radeon_add_buffer(struct radeon_winsys
* winsys
,
38 struct pipe_buffer
* pbuffer
,
42 struct radeon_bo
* bo
= ((struct radeon_pipe_buffer
*)pbuffer
)->bo
;
44 radeon_cs_space_add_persistent_bo(winsys
->priv
->cs
, bo
, rd
, wd
);
48 static boolean
radeon_validate(struct radeon_winsys
* winsys
)
50 if (radeon_cs_space_check(winsys
->priv
->cs
) < 0) {
54 /* Things are fine, we can proceed as normal. */
58 static boolean
radeon_check_cs(struct radeon_winsys
* winsys
, int size
)
60 struct radeon_cs
* cs
= winsys
->priv
->cs
;
62 return radeon_validate(winsys
) && cs
->cdw
+ size
<= cs
->ndw
;
65 static void radeon_begin_cs(struct radeon_winsys
* winsys
,
71 radeon_cs_begin(winsys
->priv
->cs
, size
, file
, function
, line
);
74 static void radeon_write_cs_dword(struct radeon_winsys
* winsys
,
77 radeon_cs_write_dword(winsys
->priv
->cs
, dword
);
80 static void radeon_write_cs_reloc(struct radeon_winsys
* winsys
,
81 struct pipe_buffer
* pbuffer
,
87 struct radeon_pipe_buffer
* radeon_buffer
=
88 (struct radeon_pipe_buffer
*)pbuffer
;
90 assert(!radeon_buffer
->pb
);
92 retval
= radeon_cs_write_reloc(winsys
->priv
->cs
, radeon_buffer
->bo
,
96 debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n",
97 pbuffer
, rd
, wd
, flags
);
101 static void radeon_reset_bos(struct radeon_winsys
*winsys
)
103 radeon_cs_space_reset_bos(winsys
->priv
->cs
);
106 static void radeon_end_cs(struct radeon_winsys
* winsys
,
108 const char* function
,
111 radeon_cs_end(winsys
->priv
->cs
, file
, function
, line
);
114 static void radeon_flush_cs(struct radeon_winsys
* winsys
)
118 /* Don't flush a zero-sized CS. */
119 if (!winsys
->priv
->cs
->cdw
) {
124 retval
= radeon_cs_emit(winsys
->priv
->cs
);
126 debug_printf("radeon: Bad CS, dumping...\n");
127 radeon_cs_print(winsys
->priv
->cs
, stderr
);
131 * Someday, when we care about performance, we should really find a way
132 * to rotate between two or three CS objects so that the GPU can be
133 * spinning through one CS while another one is being filled. */
134 radeon_cs_erase(winsys
->priv
->cs
);
138 radeon_setup_winsys(int fd
, struct radeon_winsys
* winsys
)
140 struct radeon_winsys_priv
* priv
= winsys
->priv
;
142 priv
->csm
= radeon_cs_manager_gem_ctor(fd
);
144 /* Size limit on IBs is 64 kibibytes. */
145 priv
->cs
= radeon_cs_create(priv
->csm
, 1024 * 64 / 4);
146 radeon_cs_set_limit(priv
->cs
,
147 RADEON_GEM_DOMAIN_GTT
, winsys
->gart_size
);
148 radeon_cs_set_limit(priv
->cs
,
149 RADEON_GEM_DOMAIN_VRAM
, winsys
->vram_size
);
151 winsys
->add_buffer
= radeon_add_buffer
;
152 winsys
->validate
= radeon_validate
;
154 winsys
->check_cs
= radeon_check_cs
;
155 winsys
->begin_cs
= radeon_begin_cs
;
156 winsys
->write_cs_dword
= radeon_write_cs_dword
;
157 winsys
->write_cs_reloc
= radeon_write_cs_reloc
;
158 winsys
->end_cs
= radeon_end_cs
;
159 winsys
->flush_cs
= radeon_flush_cs
;
160 winsys
->reset_bos
= radeon_reset_bos
;
161 winsys
->set_flush_cb
= radeon_set_flush_cb
;