1 #include "pipe/p_defines.h"
2 #include "pipe/p_screen.h"
3 #include "pipe/p_state.h"
5 #include "util/u_memory.h"
6 #include "util/u_inlines.h"
7 #include "util/u_format.h"
8 #include "util/u_format_s3tc.h"
9 #include "util/u_string.h"
14 #include "nouveau/nouveau_bo.h"
15 #include "nouveau_winsys.h"
16 #include "nouveau_screen.h"
18 /* XXX this should go away */
19 #include "state_tracker/drm_driver.h"
20 #include "util/u_simple_screen.h"
23 nouveau_screen_get_name(struct pipe_screen
*pscreen
)
25 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
26 static char buffer
[128];
28 util_snprintf(buffer
, sizeof(buffer
), "NV%02X", dev
->chipset
);
33 nouveau_screen_get_vendor(struct pipe_screen
*pscreen
)
41 nouveau_screen_bo_new(struct pipe_screen
*pscreen
, unsigned alignment
,
42 unsigned usage
, unsigned bind
, unsigned size
)
44 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
45 struct nouveau_bo
*bo
= NULL
;
46 uint32_t flags
= NOUVEAU_BO_MAP
, tile_mode
= 0, tile_flags
= 0;
49 if (bind
& PIPE_BIND_VERTEX_BUFFER
)
50 flags
|= nouveau_screen(pscreen
)->vertex_buffer_flags
;
51 else if (bind
& PIPE_BIND_INDEX_BUFFER
)
52 flags
|= nouveau_screen(pscreen
)->index_buffer_flags
;
54 if (bind
& (PIPE_BIND_RENDER_TARGET
|
55 PIPE_BIND_DEPTH_STENCIL
|
57 PIPE_BIND_DISPLAY_TARGET
|
58 PIPE_BIND_SAMPLER_VIEW
))
60 /* TODO: this may be incorrect or suboptimal */
61 if (!(bind
& PIPE_BIND_SCANOUT
))
62 flags
|= NOUVEAU_BO_GART
;
63 if (usage
!= PIPE_USAGE_DYNAMIC
)
64 flags
|= NOUVEAU_BO_VRAM
;
66 if (dev
->chipset
== 0x50 || dev
->chipset
>= 0x80) {
67 if (bind
& PIPE_BIND_DEPTH_STENCIL
)
74 ret
= nouveau_bo_new_tile(dev
, flags
, alignment
, size
,
75 tile_mode
, tile_flags
, &bo
);
83 nouveau_screen_bo_user(struct pipe_screen
*pscreen
, void *ptr
, unsigned bytes
)
85 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
86 struct nouveau_bo
*bo
= NULL
;
89 ret
= nouveau_bo_user(dev
, ptr
, bytes
, &bo
);
97 nouveau_screen_bo_map(struct pipe_screen
*pscreen
,
98 struct nouveau_bo
*bo
,
103 ret
= nouveau_bo_map(bo
, map_flags
);
105 debug_printf("map failed: %d\n", ret
);
113 nouveau_screen_bo_map_range(struct pipe_screen
*pscreen
, struct nouveau_bo
*bo
,
114 unsigned offset
, unsigned length
, unsigned flags
)
118 ret
= nouveau_bo_map_range(bo
, offset
, length
, flags
);
120 nouveau_bo_unmap(bo
);
121 if (!(flags
& NOUVEAU_BO_NOWAIT
) || ret
!= -EBUSY
)
122 debug_printf("map_range failed: %d\n", ret
);
126 return (char *)bo
->map
- offset
; /* why gallium? why? */
130 nouveau_screen_bo_map_flush_range(struct pipe_screen
*pscreen
, struct nouveau_bo
*bo
,
131 unsigned offset
, unsigned length
)
133 nouveau_bo_map_flush(bo
, offset
, length
);
137 nouveau_screen_bo_unmap(struct pipe_screen
*pscreen
, struct nouveau_bo
*bo
)
139 nouveau_bo_unmap(bo
);
143 nouveau_screen_bo_release(struct pipe_screen
*pscreen
, struct nouveau_bo
*bo
)
145 nouveau_bo_ref(NULL
, &bo
);
149 nouveau_screen_fence_ref(struct pipe_screen
*pscreen
,
150 struct pipe_fence_handle
**ptr
,
151 struct pipe_fence_handle
*pfence
)
157 nouveau_screen_fence_signalled(struct pipe_screen
*screen
,
158 struct pipe_fence_handle
*pfence
,
165 nouveau_screen_fence_finish(struct pipe_screen
*screen
,
166 struct pipe_fence_handle
*pfence
,
174 nouveau_screen_bo_from_handle(struct pipe_screen
*pscreen
,
175 struct winsys_handle
*whandle
,
176 unsigned *out_stride
)
178 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
179 struct nouveau_bo
*bo
= 0;
182 ret
= nouveau_bo_handle_ref(dev
, whandle
->handle
, &bo
);
184 debug_printf("%s: ref name 0x%08x failed with %d\n",
185 __func__
, whandle
->handle
, ret
);
189 *out_stride
= whandle
->stride
;
195 nouveau_screen_bo_get_handle(struct pipe_screen
*pscreen
,
196 struct nouveau_bo
*bo
,
198 struct winsys_handle
*whandle
)
200 whandle
->stride
= stride
;
202 if (whandle
->type
== DRM_API_HANDLE_TYPE_SHARED
) {
203 return nouveau_bo_handle_get(bo
, &whandle
->handle
) == 0;
204 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_KMS
) {
205 whandle
->handle
= bo
->handle
;
214 nouveau_reference_flags(struct nouveau_bo
*bo
)
219 bo_flags
= nouveau_bo_pending(bo
);
220 if (bo_flags
& NOUVEAU_BO_RD
)
221 flags
|= PIPE_REFERENCED_FOR_READ
;
222 if (bo_flags
& NOUVEAU_BO_WR
)
223 flags
|= PIPE_REFERENCED_FOR_WRITE
;
233 nouveau_screen_init(struct nouveau_screen
*screen
, struct nouveau_device
*dev
)
235 struct pipe_screen
*pscreen
= &screen
->base
;
238 ret
= nouveau_channel_alloc(dev
, 0xbeef0201, 0xbeef0202,
242 screen
->device
= dev
;
244 pscreen
->get_name
= nouveau_screen_get_name
;
245 pscreen
->get_vendor
= nouveau_screen_get_vendor
;
247 pscreen
->fence_reference
= nouveau_screen_fence_ref
;
248 pscreen
->fence_signalled
= nouveau_screen_fence_signalled
;
249 pscreen
->fence_finish
= nouveau_screen_fence_finish
;
251 util_format_s3tc_init();
257 nouveau_screen_fini(struct nouveau_screen
*screen
)
259 struct pipe_winsys
*ws
= screen
->base
.winsys
;
260 nouveau_channel_free(&screen
->channel
);