2 #include "i915simple/i915_debug.h"
3 #include "intel_be_batchbuffer.h"
4 #include "intel_be_context.h"
5 #include "intel_be_device.h"
6 #include "intel_be_fence.h"
9 #include "util/u_memory.h"
11 struct intel_be_batchbuffer
*
12 intel_be_batchbuffer_alloc(struct intel_be_context
*intel
)
14 struct intel_be_batchbuffer
*batch
= CALLOC_STRUCT(intel_be_batchbuffer
);
17 batch
->base
.buffer
= NULL
;
18 batch
->base
.winsys
= &intel
->base
;
19 batch
->base
.map
= NULL
;
20 batch
->base
.ptr
= NULL
;
22 batch
->base
.actual_size
= intel
->device
->max_batch_size
;
23 batch
->base
.relocs
= 0;
24 batch
->base
.max_relocs
= 500;/*INTEL_DEFAULT_RELOCS;*/
26 batch
->base
.map
= malloc(batch
->base
.actual_size
);
27 memset(batch
->base
.map
, 0, batch
->base
.actual_size
);
29 batch
->base
.ptr
= batch
->base
.map
;
31 intel_be_batchbuffer_reset(batch
);
37 intel_be_batchbuffer_reset(struct intel_be_batchbuffer
*batch
)
39 struct intel_be_context
*intel
= intel_be_context(batch
->base
.winsys
);
40 struct intel_be_device
*dev
= intel
->device
;
43 drm_intel_bo_unreference(batch
->bo
);
45 memset(batch
->base
.map
, 0, batch
->base
.actual_size
);
46 batch
->base
.ptr
= batch
->base
.map
;
47 batch
->base
.size
= batch
->base
.actual_size
- BATCH_RESERVED
;
49 batch
->base
.relocs
= 0;
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 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x4<<23)|(1<<0)); // MI_FLUSH | FLUSH_MAP_CACHE;
99 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x0<<23)); // MI_NOOP
100 i915_batchbuffer_dword(i915
, (0x0<<29)|(0xA<<23)); // MI_BATCH_BUFFER_END;
102 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x4<<23)|(1<<0)); //MI_FLUSH | FLUSH_MAP_CACHE;
103 i915_batchbuffer_dword(i915
, (0x0<<29)|(0xA<<23)); // MI_BATCH_BUFFER_END;
106 used
= batch
->base
.ptr
- batch
->base
.map
;
108 drm_intel_bo_subdata(batch
->bo
, 0, used
, batch
->base
.map
);
109 ret
= drm_intel_bo_exec(batch
->bo
, used
, NULL
, 0, 0);
113 intel_be_batchbuffer_reset(batch
);
117 intel_be_fence_reference(fence
, NULL
);
119 (*fence
) = CALLOC_STRUCT(intel_be_fence
);
120 pipe_reference_init(&(*fence
)->reference
, 1);
126 intel_be_batchbuffer_finish(struct intel_be_batchbuffer
*batch
)
132 intel_be_batchbuffer_free(struct intel_be_batchbuffer
*batch
)
135 drm_intel_bo_unreference(batch
->bo
);
137 free(batch
->base
.map
);