2 #include "state_tracker/drm_api.h"
4 #include "i965_drm_winsys.h"
5 #include "util/u_memory.h"
7 #include "brw/brw_context.h" /* XXX: shouldn't be doing this */
8 #include "brw/brw_screen.h" /* XXX: shouldn't be doing this */
10 #include "trace/tr_drm.h"
18 i965_drm_get_device_id(unsigned int *device_id
)
25 * FIXME: Fix this up to use a drm ioctl or whatever.
28 snprintf(path
, sizeof(path
), "/sys/class/drm/card0/device/device");
29 file
= fopen(path
, "r");
34 shutup_gcc
= fgets(path
, sizeof(path
), file
);
35 sscanf(path
, "%x", device_id
);
39 static struct i965_buffer
*
40 i965_drm_buffer_from_handle(struct i965_drm_winsys
*idws
,
41 const char* name
, unsigned handle
)
43 struct i965_drm_buffer
*buf
= CALLOC_STRUCT(i965_drm_buffer
);
44 uint32_t tile
= 0, swizzle
= 0;
49 buf
->magic
= 0xDEAD1337;
50 buf
->bo
= drm_i965_bo_gem_create_from_name(idws
->pools
.gem
, name
, handle
);
57 drm_i965_bo_get_tiling(buf
->bo
, &tile
, &swizzle
);
58 if (tile
!= I965_TILE_NONE
)
61 return (struct i965_buffer
*)buf
;
74 static struct pipe_texture
*
75 i965_drm_texture_from_shared_handle(struct drm_api
*api
,
76 struct pipe_screen
*screen
,
77 struct pipe_texture
*templ
,
82 struct i965_drm_winsys
*idws
= i965_drm_winsys(i965_screen(screen
)->iws
);
83 struct i965_buffer
*buffer
;
85 buffer
= i965_drm_buffer_from_handle(idws
, name
, handle
);
89 return i965_texture_blanket_i965(screen
, templ
, pitch
, buffer
);
93 i965_drm_shared_handle_from_texture(struct drm_api
*api
,
94 struct pipe_screen
*screen
,
95 struct pipe_texture
*texture
,
99 struct i965_drm_buffer
*buf
= NULL
;
100 struct i965_buffer
*buffer
= NULL
;
101 if (!i965_get_texture_buffer_i965(texture
, &buffer
, pitch
))
104 buf
= i965_drm_buffer(buffer
);
106 if (drm_i965_bo_flink(buf
->bo
, &buf
->flink
))
111 *handle
= buf
->flink
;
117 i965_drm_local_handle_from_texture(struct drm_api
*api
,
118 struct pipe_screen
*screen
,
119 struct pipe_texture
*texture
,
123 struct i965_buffer
*buffer
= NULL
;
124 if (!i965_get_texture_buffer_i965(texture
, &buffer
, pitch
))
127 *handle
= i965_drm_buffer(buffer
)->bo
->handle
;
133 i965_drm_winsys_destroy(struct i965_winsys
*iws
)
135 struct i965_drm_winsys
*idws
= i965_drm_winsys(iws
);
137 drm_i965_bufmgr_destroy(idws
->pools
.gem
);
142 static struct pipe_screen
*
143 i965_drm_create_screen(struct drm_api
*api
, int drmFD
,
144 struct drm_create_screen_arg
*arg
)
146 struct i965_drm_winsys
*idws
;
147 unsigned int deviceID
;
151 case DRM_CREATE_NORMAL
:
158 idws
= CALLOC_STRUCT(i965_drm_winsys
);
162 i965_drm_get_device_id(&deviceID
);
164 i965_drm_winsys_init_batchbuffer_functions(idws
);
165 i965_drm_winsys_init_buffer_functions(idws
);
166 i965_drm_winsys_init_fence_functions(idws
);
170 idws
->max_batch_size
= 16 * 4096;
172 idws
->base
.destroy
= i965_drm_winsys_destroy
;
174 idws
->pools
.gem
= drm_i965_bufmgr_gem_init(idws
->fd
, idws
->max_batch_size
);
175 drm_i965_bufmgr_gem_enable_reuse(idws
->pools
.gem
);
177 idws
->softpipe
= FALSE
;
178 idws
->dump_cmd
= debug_get_bool_option("I965_DUMP_CMD", FALSE
);
180 return i965_create_screen(&idws
->base
, deviceID
);
183 static struct pipe_context
*
184 i965_drm_create_context(struct drm_api
*api
, struct pipe_screen
*screen
)
186 return i965_create_context(screen
);
190 destroy(struct drm_api
*api
)
195 struct drm_api i965_drm_api
=
197 .create_context
= i965_drm_create_context
,
198 .create_screen
= i965_drm_create_screen
,
199 .texture_from_shared_handle
= i965_drm_texture_from_shared_handle
,
200 .shared_handle_from_texture
= i965_drm_shared_handle_from_texture
,
201 .local_handle_from_texture
= i965_drm_local_handle_from_texture
,
208 return trace_drm_create(&i965_drm_api
);