i915g: s/__func__/__FUNCTION__/
[mesa.git] / src / gallium / winsys / i915 / sw / i915_sw_batchbuffer.c
1
2 #include "i915_sw_winsys.h"
3 #include "i915/i915_batchbuffer.h"
4 #include "util/u_memory.h"
5
6 #define BATCH_RESERVED 16
7
8 #define INTEL_DEFAULT_RELOCS 100
9 #define INTEL_MAX_RELOCS 400
10
11 #define INTEL_BATCH_NO_CLIPRECTS 0x1
12 #define INTEL_BATCH_CLIPRECTS 0x2
13
14 #define INTEL_ALWAYS_FLUSH
15
16 struct i915_sw_batchbuffer
17 {
18 struct i915_winsys_batchbuffer base;
19
20 size_t actual_size;
21 };
22
23 static INLINE struct i915_sw_batchbuffer *
24 i915_sw_batchbuffer(struct i915_winsys_batchbuffer *batch)
25 {
26 return (struct i915_sw_batchbuffer *)batch;
27 }
28
29 static void
30 i915_sw_batchbuffer_reset(struct i915_sw_batchbuffer *batch)
31 {
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;
36 }
37
38 static struct i915_winsys_batchbuffer *
39 i915_sw_batchbuffer_create(struct i915_winsys *iws)
40 {
41 struct i915_sw_winsys *isws = i915_sw_winsys(iws);
42 struct i915_sw_batchbuffer *batch = CALLOC_STRUCT(i915_sw_batchbuffer);
43
44 batch->actual_size = isws->max_batch_size;
45
46 batch->base.map = MALLOC(batch->actual_size);
47 batch->base.ptr = NULL;
48 batch->base.size = 0;
49
50 batch->base.relocs = 0;
51 batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/
52
53 batch->base.iws = iws;
54
55 i915_sw_batchbuffer_reset(batch);
56
57 return &batch->base;
58 }
59
60 static int
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)
65 {
66 struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch);
67 int ret = 0;
68
69 assert(batch->base.relocs < batch->base.max_relocs);
70
71 if (usage == I915_USAGE_SAMPLER) {
72
73 } else if (usage == I915_USAGE_RENDER) {
74
75 } else if (usage == I915_USAGE_2D_TARGET) {
76
77 } else if (usage == I915_USAGE_2D_SOURCE) {
78
79 } else if (usage == I915_USAGE_VERTEX) {
80
81 } else {
82 assert(0);
83 return -1;
84 }
85
86 ((uint32_t*)batch->base.ptr)[0] = 0;
87 batch->base.ptr += 4;
88
89 if (!ret)
90 batch->base.relocs++;
91
92 return ret;
93 }
94
95 static void
96 i915_sw_batchbuffer_flush(struct i915_winsys_batchbuffer *ibatch,
97 struct pipe_fence_handle **fence)
98 {
99 struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch);
100 unsigned used = 0;
101 int i;
102
103 assert(i915_winsys_batchbuffer_space(ibatch) >= 0);
104
105 used = batch->base.ptr - batch->base.map;
106 assert((used & 3) == 0);
107
108 #ifdef INTEL_ALWAYS_FLUSH
109 /* MI_FLUSH | FLUSH_MAP_CACHE */
110 i915_winsys_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0));
111 used += 4;
112 #endif
113
114 if ((used & 4) == 0) {
115 /* MI_NOOP */
116 i915_winsys_batchbuffer_dword(ibatch, 0);
117 }
118 /* MI_BATCH_BUFFER_END */
119 i915_winsys_batchbuffer_dword(ibatch, (0xA<<23));
120
121 used = batch->base.ptr - batch->base.map;
122 assert((used & 4) == 0);
123
124 if (i915_sw_winsys(ibatch->iws)->dump_cmd) {
125 unsigned *ptr = (unsigned *)batch->base.map;
126
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);
130 }
131 }
132
133 if (fence) {
134 ibatch->iws->fence_reference(ibatch->iws, fence, NULL);
135
136 (*fence) = i915_sw_fence_create();
137 }
138
139 i915_sw_batchbuffer_reset(batch);
140 }
141
142 static void
143 i915_sw_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch)
144 {
145 struct i915_sw_batchbuffer *batch = i915_sw_batchbuffer(ibatch);
146
147 FREE(batch->base.map);
148 FREE(batch);
149 }
150
151 void i915_sw_winsys_init_batchbuffer_functions(struct i915_sw_winsys *isws)
152 {
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;
157 }