2 #include "i915_sw_winsys.h"
3 #include "i915/i915_batchbuffer.h"
4 #include "util/u_memory.h"
6 #define BATCH_RESERVED 16
8 #define INTEL_DEFAULT_RELOCS 100
9 #define INTEL_MAX_RELOCS 400
11 #define INTEL_BATCH_NO_CLIPRECTS 0x1
12 #define INTEL_BATCH_CLIPRECTS 0x2
14 #define INTEL_ALWAYS_FLUSH
16 struct i915_sw_batchbuffer
18 struct i915_winsys_batchbuffer base
;
23 static INLINE
struct i915_sw_batchbuffer
*
24 i915_sw_batchbuffer(struct i915_winsys_batchbuffer
*batch
)
26 return (struct i915_sw_batchbuffer
*)batch
;
30 i915_sw_batchbuffer_reset(struct i915_sw_batchbuffer
*batch
)
32 memset(batch
->base
.map
, 0, batch
->actual_size
);
33 batch
->base
.ptr
= batch
->base
.map
;
34 batch
->base
.size
= batch
->actual_size
- BATCH_RESERVED
;
35 batch
->base
.relocs
= 0;
38 static struct i915_winsys_batchbuffer
*
39 i915_sw_batchbuffer_create(struct i915_winsys
*iws
)
41 struct i915_sw_winsys
*isws
= i915_sw_winsys(iws
);
42 struct i915_sw_batchbuffer
*batch
= CALLOC_STRUCT(i915_sw_batchbuffer
);
44 batch
->actual_size
= isws
->max_batch_size
;
46 batch
->base
.map
= MALLOC(batch
->actual_size
);
47 batch
->base
.ptr
= NULL
;
50 batch
->base
.relocs
= 0;
51 batch
->base
.max_relocs
= 300;/*INTEL_DEFAULT_RELOCS;*/
53 batch
->base
.iws
= iws
;
55 i915_sw_batchbuffer_reset(batch
);
61 i915_sw_batchbuffer_reloc(struct i915_winsys_batchbuffer
*ibatch
,
62 struct i915_winsys_buffer
*buffer
,
63 enum i915_winsys_buffer_usage usage
,
64 unsigned pre_add
, bool fenced
)
66 struct i915_sw_batchbuffer
*batch
= i915_sw_batchbuffer(ibatch
);
69 assert(batch
->base
.relocs
< batch
->base
.max_relocs
);
71 if (usage
== I915_USAGE_SAMPLER
) {
73 } else if (usage
== I915_USAGE_RENDER
) {
75 } else if (usage
== I915_USAGE_2D_TARGET
) {
77 } else if (usage
== I915_USAGE_2D_SOURCE
) {
79 } else if (usage
== I915_USAGE_VERTEX
) {
86 ((uint32_t*)batch
->base
.ptr
)[0] = 0;
96 i915_sw_batchbuffer_flush(struct i915_winsys_batchbuffer
*ibatch
,
97 struct pipe_fence_handle
**fence
)
99 struct i915_sw_batchbuffer
*batch
= i915_sw_batchbuffer(ibatch
);
103 assert(i915_winsys_batchbuffer_space(ibatch
) >= 0);
105 used
= batch
->base
.ptr
- batch
->base
.map
;
106 assert((used
& 3) == 0);
108 #ifdef INTEL_ALWAYS_FLUSH
109 /* MI_FLUSH | FLUSH_MAP_CACHE */
110 i915_winsys_batchbuffer_dword(ibatch
, (0x4<<23)|(1<<0));
114 if ((used
& 4) == 0) {
116 i915_winsys_batchbuffer_dword(ibatch
, 0);
118 /* MI_BATCH_BUFFER_END */
119 i915_winsys_batchbuffer_dword(ibatch
, (0xA<<23));
121 used
= batch
->base
.ptr
- batch
->base
.map
;
122 assert((used
& 4) == 0);
124 if (i915_sw_winsys(ibatch
->iws
)->dump_cmd
) {
125 unsigned *ptr
= (unsigned *)batch
->base
.map
;
127 debug_printf("%s:\n", __FUNCTION__
);
128 for (i
= 0; i
< used
/ 4; i
++, ptr
++) {
129 debug_printf("\t%08x: %08x\n", i
*4, *ptr
);
134 ibatch
->iws
->fence_reference(ibatch
->iws
, fence
, NULL
);
136 (*fence
) = i915_sw_fence_create();
139 i915_sw_batchbuffer_reset(batch
);
143 i915_sw_batchbuffer_destroy(struct i915_winsys_batchbuffer
*ibatch
)
145 struct i915_sw_batchbuffer
*batch
= i915_sw_batchbuffer(ibatch
);
147 FREE(batch
->base
.map
);
151 void i915_sw_winsys_init_batchbuffer_functions(struct i915_sw_winsys
*isws
)
153 isws
->base
.batchbuffer_create
= i915_sw_batchbuffer_create
;
154 isws
->base
.batchbuffer_reloc
= i915_sw_batchbuffer_reloc
;
155 isws
->base
.batchbuffer_flush
= i915_sw_batchbuffer_flush
;
156 isws
->base
.batchbuffer_destroy
= i915_sw_batchbuffer_destroy
;