2 #include "intel_be_batchbuffer.h"
3 #include "intel_be_context.h"
4 #include "intel_be_device.h"
5 #include "intel_be_fence.h"
8 #include "util/u_memory.h"
10 struct intel_be_batchbuffer
*
11 intel_be_batchbuffer_alloc(struct intel_be_context
*intel
)
13 struct intel_be_batchbuffer
*batch
= CALLOC_STRUCT(intel_be_batchbuffer
);
16 batch
->base
.buffer
= NULL
;
17 batch
->base
.winsys
= &intel
->base
;
18 batch
->base
.map
= NULL
;
19 batch
->base
.ptr
= NULL
;
21 batch
->base
.actual_size
= intel
->device
->max_batch_size
;
22 batch
->base
.relocs
= 0;
23 batch
->base
.max_relocs
= INTEL_DEFAULT_RELOCS
;
25 batch
->base
.map
= malloc(batch
->base
.actual_size
);
26 memset(batch
->base
.map
, 0, batch
->base
.actual_size
);
28 batch
->base
.ptr
= batch
->base
.map
;
30 intel_be_batchbuffer_reset(batch
);
36 intel_be_batchbuffer_reset(struct intel_be_batchbuffer
*batch
)
38 struct intel_be_context
*intel
= intel_be_context(batch
->base
.winsys
);
39 struct intel_be_device
*dev
= intel
->device
;
42 drm_intel_bo_unreference(batch
->bo
);
44 memset(batch
->base
.map
, 0, batch
->base
.actual_size
);
45 batch
->base
.ptr
= batch
->base
.map
;
46 batch
->base
.size
= batch
->base
.actual_size
- BATCH_RESERVED
;
48 batch
->base
.relocs
= 0;
49 batch
->base
.max_relocs
= INTEL_DEFAULT_RELOCS
;
51 batch
->bo
= drm_intel_bo_alloc(dev
->pools
.gem
,
52 "gallium3d_batch_buffer",
53 batch
->base
.actual_size
, 0);
57 intel_be_offset_relocation(struct intel_be_batchbuffer
*batch
,
60 uint32_t read_domains
,
61 uint32_t write_domain
)
66 assert(batch
->base
.relocs
< batch
->base
.max_relocs
);
68 offset
= (unsigned)(batch
->base
.ptr
- batch
->base
.map
);
70 ret
= drm_intel_bo_emit_reloc(batch
->bo
, offset
,
75 ((uint32_t*)batch
->base
.ptr
)[0] = bo
->offset
+ pre_add
;
85 intel_be_batchbuffer_flush(struct intel_be_batchbuffer
*batch
,
86 struct intel_be_fence
**fence
)
88 struct i915_batchbuffer
*i915
= &batch
->base
;
92 assert(i915_batchbuffer_space(i915
) >= 0);
94 used
= batch
->base
.ptr
- batch
->base
.map
;
95 assert((used
& 3) == 0);
98 ((uint32_t *) batch
->base
.ptr
)[0] = ((0<<29)|(4<<23)); // MI_FLUSH;
99 ((uint32_t *) batch
->base
.ptr
)[1] = 0;
100 ((uint32_t *) batch
->base
.ptr
)[2] = (0xA<<23); // MI_BATCH_BUFFER_END;
101 batch
->base
.ptr
+= 12;
103 ((uint32_t *) batch
->base
.ptr
)[0] = ((0<<29)|(4<<23)); // MI_FLUSH;
104 ((uint32_t *) batch
->base
.ptr
)[1] = (0xA<<23); // MI_BATCH_BUFFER_END;
105 batch
->base
.ptr
+= 8;
108 debug_printf("%s\n", __FUNCTION__
);
110 used
= batch
->base
.ptr
- batch
->base
.map
;
112 debug_printf(" - subdata\n");
113 drm_intel_bo_subdata(batch
->bo
, 0, used
, batch
->base
.map
);
114 debug_printf(" - exec\n");
115 ret
= drm_intel_bo_exec(batch
->bo
, used
, NULL
, 0, 0);
116 debug_printf(" - waiting\n");
117 drm_intel_bo_wait_rendering(batch
->bo
);
118 debug_printf(" - done\n");
122 intel_be_batchbuffer_reset(batch
);
126 intel_be_fence_unreference(*fence
);
128 (*fence
) = CALLOC_STRUCT(intel_be_fence
);
129 (*fence
)->refcount
= 1;
135 intel_be_batchbuffer_finish(struct intel_be_batchbuffer
*batch
)
141 intel_be_batchbuffer_free(struct intel_be_batchbuffer
*batch
)
144 drm_intel_bo_unreference(batch
->bo
);
146 free(batch
->base
.map
);