2 * Copyright 2010 Dave Airlie
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.
26 #include <pipe/p_compiler.h>
27 #include <pipe/p_screen.h>
28 #include <pipebuffer/pb_bufmgr.h>
29 #include "state_tracker/drm_driver.h"
30 #include "r600_priv.h"
33 #include "radeon_drm.h"
35 struct r600_bo
*r600_bo(struct radeon
*radeon
,
36 unsigned size
, unsigned alignment
,
37 unsigned binding
, unsigned usage
)
39 struct r600_bo
*ws_bo
= calloc(1, sizeof(struct r600_bo
));
41 struct pb_manager
*man
;
43 desc
.alignment
= alignment
;
44 desc
.usage
= (PB_USAGE_CPU_READ_WRITE
| PB_USAGE_GPU_READ_WRITE
);
47 if (binding
& (PIPE_BIND_CONSTANT_BUFFER
| PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_INDEX_BUFFER
))
52 /* Staging resources particpate in transfers and blits only
53 * and are used for uploads and downloads from regular
54 * resources. We generate them internally for some transfers.
56 if (usage
== PIPE_USAGE_STAGING
)
57 ws_bo
->domains
= RADEON_GEM_DOMAIN_CPU
| RADEON_GEM_DOMAIN_GTT
;
59 ws_bo
->domains
= (RADEON_GEM_DOMAIN_CPU
|
60 RADEON_GEM_DOMAIN_GTT
|
61 RADEON_GEM_DOMAIN_VRAM
);
64 ws_bo
->pb
= man
->create_buffer(man
, size
, &desc
);
65 if (ws_bo
->pb
== NULL
) {
70 pipe_reference_init(&ws_bo
->reference
, 1);
74 struct r600_bo
*r600_bo_handle(struct radeon
*radeon
,
75 unsigned handle
, unsigned *array_mode
)
77 struct r600_bo
*ws_bo
= calloc(1, sizeof(struct r600_bo
));
80 ws_bo
->pb
= radeon_bo_pb_create_buffer_from_handle(radeon
->kman
, handle
);
85 bo
= radeon_bo_pb_get_bo(ws_bo
->pb
);
86 ws_bo
->size
= bo
->size
;
87 ws_bo
->domains
= (RADEON_GEM_DOMAIN_CPU
|
88 RADEON_GEM_DOMAIN_GTT
|
89 RADEON_GEM_DOMAIN_VRAM
);
91 pipe_reference_init(&ws_bo
->reference
, 1);
93 radeon_bo_get_tiling_flags(radeon
, bo
, &ws_bo
->tiling_flags
,
94 &ws_bo
->kernel_pitch
);
96 if (ws_bo
->tiling_flags
) {
97 if (ws_bo
->tiling_flags
& RADEON_TILING_MICRO
)
98 *array_mode
= V_0280A0_ARRAY_1D_TILED_THIN1
;
99 if ((ws_bo
->tiling_flags
& (RADEON_TILING_MICRO
| RADEON_TILING_MACRO
)) ==
100 (RADEON_TILING_MICRO
| RADEON_TILING_MACRO
))
101 *array_mode
= V_0280A0_ARRAY_2D_TILED_THIN1
;
109 void *r600_bo_map(struct radeon
*radeon
, struct r600_bo
*bo
, unsigned usage
, void *ctx
)
111 return pb_map(bo
->pb
, usage
, ctx
);
114 void r600_bo_unmap(struct radeon
*radeon
, struct r600_bo
*bo
)
119 static void r600_bo_destroy(struct radeon
*radeon
, struct r600_bo
*bo
)
122 pb_reference(&bo
->pb
, NULL
);
126 void r600_bo_reference(struct radeon
*radeon
, struct r600_bo
**dst
,
129 struct r600_bo
*old
= *dst
;
131 if (pipe_reference(&(*dst
)->reference
, &src
->reference
)) {
132 r600_bo_destroy(radeon
, old
);
137 unsigned r600_bo_get_handle(struct r600_bo
*pb_bo
)
139 struct radeon_bo
*bo
;
141 bo
= radeon_bo_pb_get_bo(pb_bo
->pb
);
148 unsigned r600_bo_get_size(struct r600_bo
*pb_bo
)
150 struct radeon_bo
*bo
;
152 bo
= radeon_bo_pb_get_bo(pb_bo
->pb
);
159 boolean
r600_bo_get_winsys_handle(struct radeon
*radeon
, struct r600_bo
*pb_bo
,
160 unsigned stride
, struct winsys_handle
*whandle
)
162 struct radeon_bo
*bo
;
164 bo
= radeon_bo_pb_get_bo(pb_bo
->pb
);
168 whandle
->stride
= stride
;
169 switch(whandle
->type
) {
170 case DRM_API_HANDLE_TYPE_KMS
:
171 whandle
->handle
= r600_bo_get_handle(pb_bo
);
173 case DRM_API_HANDLE_TYPE_SHARED
:
174 if (radeon_bo_get_name(radeon
, bo
, &whandle
->handle
))