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
= 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;
50 batch
->base
.max_relocs
= INTEL_DEFAULT_RELOCS
;
52 batch
->bo
= drm_intel_bo_alloc(dev
->pools
.gem
,
53 "gallium3d_batch_buffer",
54 batch
->base
.actual_size
, 0);
58 intel_be_offset_relocation(struct intel_be_batchbuffer
*batch
,
61 uint32_t read_domains
,
62 uint32_t write_domain
)
67 assert(batch
->base
.relocs
< batch
->base
.max_relocs
);
69 offset
= (unsigned)(batch
->base
.ptr
- batch
->base
.map
);
71 ret
= drm_intel_bo_emit_reloc(batch
->bo
, offset
,
76 ((uint32_t*)batch
->base
.ptr
)[0] = bo
->offset
+ pre_add
;
86 intel_be_batchbuffer_flush(struct intel_be_batchbuffer
*batch
,
87 struct intel_be_fence
**fence
)
89 struct i915_batchbuffer
*i915
= &batch
->base
;
93 assert(i915_batchbuffer_space(i915
) >= 0);
95 used
= batch
->base
.ptr
- batch
->base
.map
;
96 assert((used
& 3) == 0);
99 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x4<<23)|(1<<0)); // MI_FLUSH | FLUSH_MAP_CACHE;
100 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x0<<23)); // MI_NOOP
101 i915_batchbuffer_dword(i915
, (0x0<<29)|(0xA<<23)); // MI_BATCH_BUFFER_END;
103 i915_batchbuffer_dword(i915
, (0x0<<29)|(0x4<<23)|(1<<0)); //MI_FLUSH | FLUSH_MAP_CACHE;
104 i915_batchbuffer_dword(i915
, (0x0<<29)|(0xA<<23)); // MI_BATCH_BUFFER_END;
107 used
= batch
->base
.ptr
- batch
->base
.map
;
109 drm_intel_bo_subdata(batch
->bo
, 0, used
, batch
->base
.map
);
110 ret
= drm_intel_bo_exec(batch
->bo
, used
, NULL
, 0, 0);
114 intel_be_batchbuffer_reset(batch
);
118 intel_be_fence_unreference(*fence
);
120 (*fence
) = CALLOC_STRUCT(intel_be_fence
);
121 (*fence
)->refcount
= 1;
127 intel_be_batchbuffer_finish(struct intel_be_batchbuffer
*batch
)
133 intel_be_batchbuffer_free(struct intel_be_batchbuffer
*batch
)
136 drm_intel_bo_unreference(batch
->bo
);
138 free(batch
->base
.map
);